// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// 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.
//
// BOINC 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see .
// 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
#include
#include "config.h"
#include "error_numbers.h"
#include "filesys.h"
#include "parse.h"
#include "str_replace.h"
#include "util.h"
#include "sched_util.h"
#include "sched_config.h"
#include "sched_msgs.h"
#include "validator.h"
#include "validate_util.h"
using std::vector;
using std::string;
bool standalone = false;
////////// functions for locating output files ///////////////
int OUTPUT_FILE_INFO::parse(XML_PARSER& xp) {
bool found=false;
optional = false;
no_validate = false;
while (!xp.get_tag()) {
if (!xp.is_tag) continue;
if (xp.match_tag("/file_ref")) {
return found?0:ERR_XML_PARSE;
}
if (xp.parse_string("file_name", name)) {
found = true;
continue;
}
if (xp.parse_bool("optional", optional)) continue;
if (xp.parse_bool("no_validate", no_validate)) continue;
}
return ERR_XML_PARSE;
}
int get_output_file_info(RESULT& result, OUTPUT_FILE_INFO& fi) {
char path[MAXPATHLEN];
string name;
MIOFILE mf;
mf.init_buf_read(result.xml_doc_in);
XML_PARSER xp(&mf);
while (!xp.get_tag()) {
if (!xp.is_tag) continue;
if (xp.match_tag("file_ref")) {
int retval = fi.parse(xp);
if (retval) return retval;
if (standalone) {
safe_strcpy(path, fi.name.c_str());
} else {
dir_hier_path(
fi.name.c_str(), config.upload_dir,
config.uldl_dir_fanout, path
);
}
fi.path = path;
return 0;
}
}
return ERR_XML_PARSE;
}
int get_output_file_infos(RESULT& result, vector& fis) {
char path[MAXPATHLEN];
MIOFILE mf;
string name;
mf.init_buf_read(result.xml_doc_in);
XML_PARSER xp(&mf);
fis.clear();
while (!xp.get_tag()) {
if (!xp.is_tag) continue;
if (xp.match_tag("file_ref")) {
OUTPUT_FILE_INFO fi;
int retval = fi.parse(xp);
if (retval) return retval;
if (standalone) {
safe_strcpy(path, fi.name.c_str());
} else {
dir_hier_path(
fi.name.c_str(), config.upload_dir,
config.uldl_dir_fanout, path
);
}
fi.path = path;
fis.push_back(fi);
}
}
return 0;
}
int get_output_file_path(RESULT& result, string& path) {
OUTPUT_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& paths) {
vector fis;
int retval = get_output_file_infos(result, fis);
if (retval) return retval;
paths.clear();
for (unsigned int i=0; i&, double& credit) {
double x;
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, "", x)) {
credit = x;
return 0;
}
}
return ERR_XML_PARSE;
}
const char *BOINC_RCSID_07049e8a0e = "$Id$";