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
|
|
|
|
|
2002-10-03 18:33:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#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
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
const char* CONFIG_FILE = "config.xml";
|
2003-07-08 21:30:47 +00:00
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
int SCHED_CONFIG::parse(FILE* in) {
|
2003-08-15 22:39:56 +00:00
|
|
|
char buf[256];
|
2002-10-03 18:33:46 +00:00
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
memset(this, 0, sizeof(SCHED_CONFIG));
|
2002-10-03 18:33:46 +00:00
|
|
|
while (fgets(buf, 256, in)) {
|
|
|
|
if (match_tag(buf, "</config>")) return 0;
|
|
|
|
else if (parse_str(buf, "<db_name>", db_name, sizeof(db_name))) continue;
|
|
|
|
else if (parse_str(buf, "<db_passwd>", db_passwd, sizeof(db_passwd))) continue;
|
|
|
|
else if (parse_int(buf, "<shmem_key>", shmem_key)) continue;
|
|
|
|
else if (parse_str(buf, "<key_dir>", key_dir, sizeof(key_dir))) continue;
|
2002-10-14 23:10:12 +00:00
|
|
|
else if (parse_str(buf, "<download_url>", download_url, sizeof(download_url))) continue;
|
2002-12-17 19:00:43 +00:00
|
|
|
else if (parse_str(buf, "<download_dir>", download_dir, sizeof(download_dir))) continue;
|
2002-10-14 23:10:12 +00:00
|
|
|
else if (parse_str(buf, "<upload_url>", upload_url, sizeof(upload_url))) continue;
|
2002-10-03 18:33:46 +00:00
|
|
|
else if (parse_str(buf, "<upload_dir>", upload_dir, sizeof(upload_dir))) continue;
|
|
|
|
else if (parse_str(buf, "<user_name>", user_name, sizeof(user_name))) continue;
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2003-09-02 21:16:55 +00:00
|
|
|
int SCHED_CONFIG::parse_file(char* dir) {
|
2002-10-03 18:33:46 +00:00
|
|
|
FILE* f;
|
2003-09-02 21:16:55 +00:00
|
|
|
char path[256];
|
|
|
|
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);
|
|
|
|
f = fopen(path, "r");
|
2002-10-03 18:33:46 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
2003-09-02 21:16:55 +00:00
|
|
|
retval = parse(f);
|
|
|
|
fclose(f);
|
|
|
|
return retval;
|
2002-10-03 18:33:46 +00:00
|
|
|
}
|