2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2003-08-14 00:02:15 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
2003-08-14 00:02:15 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// 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.
|
2003-08-14 00:02:15 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2009-08-10 04:22:02 +00:00
|
|
|
// Support functions for validators:
|
|
|
|
// 1) functions for locating the output files
|
|
|
|
// 2) various ways of deciding how much credit to grant
|
|
|
|
// a group of replicated results
|
2003-09-20 17:38:13 +00:00
|
|
|
|
2008-02-27 23:26:38 +00:00
|
|
|
#include <cstring>
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2003-09-20 17:38:13 +00:00
|
|
|
|
2003-10-21 04:06:55 +00:00
|
|
|
#include "error_numbers.h"
|
2003-08-14 00:02:15 +00:00
|
|
|
#include "parse.h"
|
2004-08-06 11:42:41 +00:00
|
|
|
#include "util.h"
|
2005-01-02 08:01:27 +00:00
|
|
|
#include "filesys.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
|
|
|
|
#include "sched_util.h"
|
|
|
|
#include "sched_config.h"
|
|
|
|
#include "sched_msgs.h"
|
2006-06-10 21:29:51 +00:00
|
|
|
#include "validator.h"
|
2003-10-21 04:06:55 +00:00
|
|
|
#include "validate_util.h"
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
2009-08-10 04:22:02 +00:00
|
|
|
////////// functions for locating output files ///////////////
|
|
|
|
|
2008-05-29 20:11:43 +00:00
|
|
|
int FILE_INFO::parse(XML_PARSER& xp) {
|
2006-10-28 18:25:35 +00:00
|
|
|
char tag[256];
|
|
|
|
bool is_tag, found=false;
|
2008-05-29 20:11:43 +00:00
|
|
|
optional = false;
|
2008-06-30 16:46:05 +00:00
|
|
|
no_validate = false;
|
2006-10-28 18:25:35 +00:00
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
2008-05-30 03:29:31 +00:00
|
|
|
if (!strcmp(tag, "/file_ref")) {
|
2006-10-28 18:25:35 +00:00
|
|
|
return found?0:ERR_XML_PARSE;
|
|
|
|
}
|
2008-05-30 03:29:31 +00:00
|
|
|
if (xp.parse_string(tag, "file_name", name)) {
|
2006-10-28 18:25:35 +00:00
|
|
|
found = true;
|
2008-05-29 20:11:43 +00:00
|
|
|
continue;
|
2006-10-28 18:25:35 +00:00
|
|
|
}
|
2008-05-29 20:11:43 +00:00
|
|
|
if (xp.parse_bool(tag, "optional", optional)) continue;
|
2008-06-30 16:46:05 +00:00
|
|
|
if (xp.parse_bool(tag, "no_validate", no_validate)) continue;
|
2006-10-28 18:25:35 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2008-05-29 21:54:18 +00:00
|
|
|
int get_output_file_info(RESULT& result, FILE_INFO& fi) {
|
2006-10-28 18:25:35 +00:00
|
|
|
char tag[256], path[1024];
|
|
|
|
bool is_tag;
|
|
|
|
string name;
|
|
|
|
MIOFILE mf;
|
2008-06-02 20:06:54 +00:00
|
|
|
mf.init_buf_read(result.xml_doc_in);
|
2006-10-28 18:25:35 +00:00
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
2008-06-30 16:46:05 +00:00
|
|
|
if (!strcmp(tag, "file_ref")) {
|
2008-05-29 20:11:43 +00:00
|
|
|
int retval = fi.parse(xp);
|
2006-10-28 18:25:35 +00:00
|
|
|
if (retval) return retval;
|
2008-05-29 20:11:43 +00:00
|
|
|
dir_hier_path(
|
|
|
|
fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
|
|
|
|
);
|
|
|
|
fi.path = path;
|
2006-10-28 18:25:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2008-05-29 21:54:18 +00:00
|
|
|
int get_output_file_infos(RESULT& result, vector<FILE_INFO>& fis) {
|
2006-10-28 18:25:35 +00:00
|
|
|
char tag[256], path[1024];
|
|
|
|
bool is_tag;
|
|
|
|
MIOFILE mf;
|
|
|
|
string name;
|
2008-05-29 21:54:18 +00:00
|
|
|
mf.init_buf_read(result.xml_doc_in);
|
2006-10-28 18:25:35 +00:00
|
|
|
XML_PARSER xp(&mf);
|
2008-05-29 20:11:43 +00:00
|
|
|
fis.clear();
|
2006-10-28 18:25:35 +00:00
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
2008-05-30 03:29:31 +00:00
|
|
|
if (!strcmp(tag, "file_ref")) {
|
2008-05-29 20:11:43 +00:00
|
|
|
FILE_INFO fi;
|
|
|
|
int retval = fi.parse(xp);
|
2006-10-28 18:25:35 +00:00
|
|
|
if (retval) return retval;
|
2008-05-29 20:11:43 +00:00
|
|
|
dir_hier_path(
|
|
|
|
fi.name.c_str(), config.upload_dir, config.uldl_dir_fanout, path
|
|
|
|
);
|
|
|
|
fi.path = path;
|
|
|
|
fis.push_back(fi);
|
2006-10-28 18:25:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2008-05-29 21:54:18 +00:00
|
|
|
int get_output_file_path(RESULT& result, string& path) {
|
|
|
|
FILE_INFO fi;
|
|
|
|
int retval = get_output_file_info(result, fi);
|
|
|
|
if (retval) return retval;
|
|
|
|
path = fi.path;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_output_file_paths(RESULT& result, vector<string>& paths) {
|
|
|
|
vector<FILE_INFO> fis;
|
|
|
|
int retval = get_output_file_infos(result, fis);
|
|
|
|
if (retval) return retval;
|
|
|
|
paths.clear();
|
|
|
|
for (unsigned int i=0; i<fis.size(); i++) {
|
|
|
|
paths.push_back(fis[i].path);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-05 20:16:10 +00:00
|
|
|
struct FILE_REF {
|
|
|
|
char file_name[256];
|
|
|
|
char open_name[256];
|
|
|
|
int parse(XML_PARSER& xp) {
|
2008-06-26 21:20:07 +00:00
|
|
|
char tag[256];
|
2008-03-05 20:16:10 +00:00
|
|
|
bool is_tag;
|
|
|
|
|
|
|
|
strcpy(file_name, "");
|
|
|
|
strcpy(open_name, "");
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
|
|
|
if (!strcmp(tag, "/file_ref")) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (xp.parse_str(tag, "file_name", file_name, sizeof(file_name))) continue;
|
|
|
|
if (xp.parse_str(tag, "open_name", open_name, sizeof(open_name))) continue;
|
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// given a path returned by the above, get the corresponding logical name
|
|
|
|
//
|
2008-05-29 20:11:43 +00:00
|
|
|
int get_logical_name(RESULT& result, string& path, string& name) {
|
2008-03-05 20:16:10 +00:00
|
|
|
char phys_name[1024];
|
|
|
|
char tag[256];
|
|
|
|
bool is_tag;
|
|
|
|
MIOFILE mf;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
mf.init_buf_read(result.xml_doc_in);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
|
|
|
|
strcpy(phys_name, path.c_str());
|
|
|
|
char* p = strrchr(phys_name, '/');
|
|
|
|
if (!p) return ERR_NOT_FOUND;
|
|
|
|
strcpy(phys_name, p+1);
|
|
|
|
|
|
|
|
while (!xp.get(tag, sizeof(tag), is_tag)) {
|
|
|
|
if (!is_tag) continue;
|
|
|
|
if (!strcmp(tag, "result")) continue;
|
|
|
|
if (!strcmp(tag, "file_ref")) {
|
|
|
|
FILE_REF fr;
|
|
|
|
retval = fr.parse(xp);
|
|
|
|
if (retval) continue;
|
|
|
|
if (!strcmp(phys_name, fr.file_name)) {
|
|
|
|
name = fr.open_name;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2008-06-26 21:20:07 +00:00
|
|
|
xp.skip_unexpected(tag, false, 0);
|
2008-03-05 20:16:10 +00:00
|
|
|
}
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
2008-08-07 22:50:05 +00:00
|
|
|
int get_credit_from_wu(WORKUNIT& wu, vector<RESULT>&, double& credit) {
|
2007-01-30 18:19:30 +00:00
|
|
|
double x;
|
2007-02-06 21:50:48 +00:00
|
|
|
int retval;
|
|
|
|
DB_WORKUNIT dbwu;
|
|
|
|
|
|
|
|
dbwu.id = wu.id;
|
|
|
|
retval = dbwu.get_field_str("xml_doc", dbwu.xml_doc, sizeof(dbwu.xml_doc));
|
|
|
|
if (!retval) {
|
|
|
|
if (parse_double(dbwu.xml_doc, "<credit>", x)) {
|
2008-08-07 22:50:05 +00:00
|
|
|
credit = x;
|
|
|
|
return 0;
|
2007-02-06 21:50:48 +00:00
|
|
|
}
|
2007-01-30 18:19:30 +00:00
|
|
|
}
|
2008-08-07 22:50:05 +00:00
|
|
|
return ERR_XML_PARSE;
|
2007-01-30 18:19:30 +00:00
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_07049e8a0e = "$Id$";
|