2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-12-03 18:57:40 +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-06-11 23:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2003-07-08 21:30:47 +00:00
|
|
|
//
|
2002-12-03 18:57:40 +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-07-08 21:30:47 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-12-03 18:57:40 +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-07-08 21:30:47 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-12-03 18:57:40 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
|
|
|
// Parse a server configuration file
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstring>
|
2003-10-03 06:46:22 +00:00
|
|
|
#include <string>
|
2004-08-03 21:51:30 +00:00
|
|
|
#include <unistd.h>
|
2002-10-03 18:33:46 +00:00
|
|
|
|
|
|
|
#include "parse.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
|
2003-08-15 00:45:25 +00:00
|
|
|
#include "sched_config.h"
|
2002-10-03 18:33:46 +00:00
|
|
|
|
2004-07-03 21:38:22 +00:00
|
|
|
#ifdef _USING_FCGI_
|
|
|
|
#include "fcgi_stdio.h"
|
|
|
|
#endif
|
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
const char* CONFIG_FILE = "config.xml";
|
2003-07-08 21:30:47 +00:00
|
|
|
|
2004-11-12 22:50:58 +00:00
|
|
|
// look for a boolean; accepts either <foobar/> or <foobar>1</foobar>
|
|
|
|
//
|
|
|
|
static void parse_bool(char* buf, char* tag, bool& result) {
|
|
|
|
char single_tag[256], start_tag[256];
|
|
|
|
int x;
|
|
|
|
|
|
|
|
sprintf(single_tag, "<%s/>", tag);
|
|
|
|
if (match_tag(buf, single_tag)) {
|
|
|
|
result = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sprintf(start_tag, "<%s>", tag);
|
|
|
|
if (parse_int(buf, start_tag, x)) {
|
|
|
|
result = (x != 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-30 23:18:56 +00:00
|
|
|
int SCHED_CONFIG::parse(char* buf) {
|
2004-02-03 21:48:49 +00:00
|
|
|
// fill in defaults
|
|
|
|
//
|
2003-09-02 21:16:55 +00:00
|
|
|
memset(this, 0, sizeof(SCHED_CONFIG));
|
2004-02-03 21:48:49 +00:00
|
|
|
max_wus_to_send = 10;
|
|
|
|
|
2004-05-02 15:55:17 +00:00
|
|
|
parse_str(buf, "<long_name>", long_name, sizeof(long_name));
|
2004-04-30 23:18:56 +00:00
|
|
|
parse_str(buf, "<db_name>", db_name, sizeof(db_name));
|
|
|
|
parse_str(buf, "<db_user>", db_user, sizeof(db_user));
|
|
|
|
parse_str(buf, "<db_passwd>", db_passwd, sizeof(db_passwd));
|
|
|
|
parse_str(buf, "<db_host>", db_host, sizeof(db_host));
|
|
|
|
parse_int(buf, "<shmem_key>", shmem_key);
|
|
|
|
parse_str(buf, "<key_dir>", key_dir, sizeof(key_dir));
|
|
|
|
parse_str(buf, "<download_url>", download_url, sizeof(download_url));
|
|
|
|
parse_str(buf, "<download_dir>", download_dir, sizeof(download_dir));
|
2004-08-06 11:42:41 +00:00
|
|
|
parse_str(buf, "<download_dir_alt>", download_dir_alt, sizeof(download_dir_alt));
|
2004-04-30 23:18:56 +00:00
|
|
|
parse_str(buf, "<upload_url>", upload_url, sizeof(upload_url));
|
|
|
|
parse_str(buf, "<upload_dir>", upload_dir, sizeof(upload_dir));
|
2004-11-12 22:50:58 +00:00
|
|
|
parse_bool(buf, "one_result_per_user_per_wu", one_result_per_user_per_wu);
|
|
|
|
parse_bool(buf, "non_cpu_intensive", non_cpu_intensive);
|
|
|
|
parse_bool(buf,"homogeneous_redundancy", homogeneous_redundancy);
|
|
|
|
parse_bool(buf, "locality_scheduling", locality_scheduling);
|
|
|
|
parse_bool(buf, "msg_to_host", msg_to_host);
|
|
|
|
parse_bool(buf, "ignore_upload_certificates", ignore_upload_certificates);
|
|
|
|
parse_bool(buf, "dont_generate_upload_certificates", dont_generate_upload_certificates);
|
2004-09-24 20:17:52 +00:00
|
|
|
#if 0
|
2004-11-12 22:50:58 +00:00
|
|
|
parse_bool(buf, "deletion_policy_priority", deletion_policy_priority);
|
|
|
|
parse_bool(buf, "deletion_policy_expire", deletion_policy_expire);
|
|
|
|
parse_bool(buf, "delete_from_self", delete_from_self);
|
2004-09-24 20:17:52 +00:00
|
|
|
#endif
|
2004-11-12 22:50:58 +00:00
|
|
|
parse_bool(buf, "enforce_delay_bound", enforce_delay_bound);
|
|
|
|
parse_bool(buf, "use_transactions", use_transactions);
|
2004-04-30 23:18:56 +00:00
|
|
|
parse_int(buf, "<min_sendwork_interval>", min_sendwork_interval);
|
|
|
|
parse_int(buf, "<max_wus_to_send>", max_wus_to_send);
|
2004-05-27 18:13:00 +00:00
|
|
|
parse_int(buf, "<daily_result_quota>", daily_result_quota);
|
2004-08-05 11:35:09 +00:00
|
|
|
parse_int(buf, "<uldl_dir_fanout>", uldl_dir_fanout);
|
2004-07-02 22:48:33 +00:00
|
|
|
if (match_tag(buf, "</config>")) {
|
|
|
|
char hostname[256];
|
|
|
|
gethostname(hostname, 256);
|
|
|
|
if (!strcmp(hostname, db_host)) strcpy(db_host, "localhost");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-03 18:33:46 +00:00
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
int SCHED_CONFIG::parse_file(char* dir) {
|
2004-04-30 23:18:56 +00:00
|
|
|
char* p;
|
2003-09-02 21:16:55 +00:00
|
|
|
char path[256];
|
2004-04-30 23:18:56 +00:00
|
|
|
int retval;
|
2002-10-03 18:33:46 +00:00
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
sprintf(path, "%s/%s", dir, CONFIG_FILE);
|
2004-04-30 23:18:56 +00:00
|
|
|
retval = read_file_malloc(path, p);
|
|
|
|
if (retval) return retval;
|
2004-08-05 11:35:09 +00:00
|
|
|
retval = parse(p);
|
|
|
|
free(p);
|
|
|
|
return retval;
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|
2004-04-04 02:59:42 +00:00
|
|
|
|
|
|
|
void get_project_dir(char* p, int len) {
|
|
|
|
getcwd(p, len);
|
|
|
|
char* q = strrchr(p, '/');
|
|
|
|
if (q) *q = 0;
|
|
|
|
}
|