- server: factor process_input_template() into smaller pieces

svn path=/trunk/boinc/; revision=24108
This commit is contained in:
David Anderson 2011-09-01 20:26:12 +00:00
parent c529c3c50d
commit f75ffd88f2
2 changed files with 251 additions and 219 deletions

View File

@ -5464,3 +5464,8 @@ David 1 Sept 2011
api/
reduce_main.cpp
David 1 Sept 2011
- server: factor process_input_template() into smaller pieces
tools/
process_input_template.cpp

View File

@ -132,40 +132,17 @@ static void write_md5_info(
return;
}
// fill in the workunit's XML document (wu.xml_doc)
// by scanning the input template, macro-substituting the input files,
// and putting in the command line element and additional XML
//
int process_input_template(
WORKUNIT& wu,
char* tmplate,
const char** infiles,
int ninfiles,
SCHED_CONFIG& config_loc,
const char* command_line,
const char* additional_xml
static int process_file_info(
XML_PARSER& xp, string& out, int ninfiles, const char** infiles,
SCHED_CONFIG& config_loc
) {
char buf[BLOB_SIZE], md5[33], path[256], url[256], top_download_path[256];
string out, cmdline, md5str, urlstr, tmpstr;
int retval, file_number;
double nbytes, nbytesdef;
char open_name[256];
bool found=false;
int nfiles_parsed = 0;
out = "";
MIOFILE mf;
XML_PARSER xp(&mf);
mf.init_buf_read(tmplate);
while (!xp.get_tag()) {
if (!xp.is_tag) continue;
if (xp.match_tag("input_template")) continue;
if (xp.match_tag("/input_template")) continue;
if (xp.match_tag("file_info")) {
vector<string> urls;
bool generated_locally = false;
file_number = nbytesdef = -1;
md5str = urlstr = "";
int retval, file_number = -1;
double nbytes, nbytesdef = -1;
string md5str, urlstr, tmpstr;
char buf[BLOB_SIZE], path[256], top_download_path[256], md5[33], url[256];
out += "<file_info>\n";
while (!xp.get_tag()) {
if (xp.parse_int("number", file_number)) {
@ -199,7 +176,6 @@ int process_input_template(
);
return ERR_XML_PARSE;
}
nfiles_parsed++;
if (generated_locally) {
sprintf(buf,
" <name>%s</name>\n"
@ -280,8 +256,20 @@ int process_input_template(
out += "\n";
}
}
} else if (xp.match_tag("workunit")) {
found = true;
return 0;
}
static int process_workunit(
XML_PARSER& xp, WORKUNIT& wu, string& out,
const char** infiles,
const char* command_line,
const char* additional_xml
) {
char buf[256], open_name[256];
int file_number;
string tmpstr, cmdline;
int retval;
out += "<workunit>\n";
if (command_line) {
//fprintf(stderr, "appending command line: %s\n", command_line);
@ -373,18 +361,57 @@ int process_input_template(
out += "\n";
}
}
return 0;
}
// fill in the workunit's XML document (wu.xml_doc)
// by scanning the input template, macro-substituting the input files,
// and putting in the command line element and additional XML
//
int process_input_template(
WORKUNIT& wu,
char* tmplate,
const char** infiles,
int ninfiles,
SCHED_CONFIG& config_loc,
const char* command_line,
const char* additional_xml
) {
string out;
int retval;
bool found_workunit=false;
int nfiles_parsed = 0;
out = "";
MIOFILE mf;
XML_PARSER xp(&mf);
mf.init_buf_read(tmplate);
while (!xp.get_tag()) {
if (!xp.is_tag) continue;
if (xp.match_tag("input_template")) continue;
if (xp.match_tag("/input_template")) continue;
if (xp.match_tag("file_info")) {
retval = process_file_info(xp, out, ninfiles, infiles, config_loc);
if (retval) return retval;
nfiles_parsed++;
} else if (xp.match_tag("workunit")) {
found_workunit = true;
retval = process_workunit(
xp, wu, out, infiles, command_line, additional_xml
);
if (retval) return retval;
}
}
if (!found) {
if (!found_workunit) {
fprintf(stderr, "process_input_template: bad WU template - no <workunit>\n");
return -1;
return ERR_XML_PARSE;
}
if (nfiles_parsed != ninfiles) {
fprintf(stderr,
"process_input_template: %d input files listed, but template has %d\n",
ninfiles, nfiles_parsed
);
return -1;
return ERR_XML_PARSE;
}
if (out.size() > sizeof(wu.xml_doc)-1) {
fprintf(stderr,