// The contents of this file are subject to the BOINC Public License // 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 // http://boinc.berkeley.edu/license_1.0.txt // // 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 // under the License. // // The Original Code is the Berkeley Open Infrastructure for Network Computing. // // The Initial Developer of the Original Code is the SETI@home project. // Portions created by the SETI@home project are Copyright (C) 2002 // University of California at Berkeley. All Rights Reserved. // // Contributor(s): // #include #include #include using namespace std; #include #include #include "parse.h" #include "error_numbers.h" #include "util.h" #include "main.h" #include "server_types.h" #include "sched_util.h" int CLIENT_APP_VERSION::parse(FILE* f) { char buf[256]; while (fgets(buf, 256, f)) { if (match_tag(buf, "")) return 0; if (parse_str(buf, "", app_name, 256)) continue; if (parse_int(buf, "", version_num)) continue; } return ERR_XML_PARSE; } SCHEDULER_REQUEST::SCHEDULER_REQUEST() { } SCHEDULER_REQUEST::~SCHEDULER_REQUEST() { } int SCHEDULER_REQUEST::parse(FILE* fin) { char buf[256]; RESULT result; int retval; strcpy(authenticator, ""); hostid = 0; work_req_seconds = 0; strcpy(global_prefs_xml, ""); strcpy(projects_xml, ""); strcpy(code_sign_key, ""); fgets(buf, 256, fin); if (!match_tag(buf, "")) return ERR_XML_PARSE; while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_str(buf, "", authenticator, sizeof(authenticator))) continue; else if (parse_int(buf, "", hostid)) continue; else if (parse_int(buf, "", rpc_seqno)) continue; else if (parse_str(buf, "", platform_name, sizeof(platform_name))) continue; else if (match_tag(buf, "")) { while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) break; if (match_tag(buf, "")) { CLIENT_APP_VERSION cav; cav.parse(fin); client_app_versions.push_back(cav); } } continue; } else if (parse_int(buf, "", core_client_major_version)) continue; else if (parse_int(buf, "", core_client_minor_version)) continue; else if (parse_int(buf, "", work_req_seconds)) continue; else if (parse_double(buf, "", project_disk_usage)) continue; else if (parse_double(buf, "", total_disk_usage)) continue; else if (match_tag(buf, "")) { strcpy(global_prefs_xml, "\n"); while (fgets(buf, 256, fin)) { if (strstr(buf, "")) break; safe_strcat(global_prefs_xml, buf); } safe_strcat(global_prefs_xml, "\n"); } else if (match_tag(buf, "")) { strcpy(projects_xml, "\n"); while (fgets(buf, 256, fin)) { if (strstr(buf, "")) break; safe_strcat(projects_xml, buf); } safe_strcat(projects_xml, "\n"); } else if (match_tag(buf, "")) { host.parse(fin); continue; } else if (match_tag(buf, "")) { host.parse_time_stats(fin); continue; } else if (match_tag(buf, "")) { host.parse_net_stats(fin); continue; } else if (match_tag(buf, "")) { result.parse_from_client(fin); results.push_back(result); continue; } else if (match_tag(buf, "")) { copy_element_contents(fin, "", code_sign_key, sizeof(code_sign_key)); } else if (match_tag(buf, "")) { TRICKLE_UP_DESC td; retval = td.parse(fin); if (!retval) { trickles.push_back(td); } } else { log_messages.printf(SchedMessages::NORMAL, "SCHEDULER_REQUEST::parse(): unrecognized: %s\n", buf); } } return ERR_XML_PARSE; } int TRICKLE_UP_DESC::parse(FILE* fin) { char buf[256]; trickle_text = ""; while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; if (parse_int(buf, "")) return 0; else if (parse_str(buf, "", name, sizeof(name))) continue; else if (parse_int(buf, "", client_state)) continue; else if (parse_double(buf, "", cpu_time)) continue; else if (parse_int(buf, "", exit_status)) continue; else if (match_tag(buf, "")) { safe_strcat(xml_doc_out, buf); while (fgets(buf, 256, fin)) { safe_strcat(xml_doc_out, buf); if (match_tag(buf, "")) break; } continue; } else if (match_tag(buf, "" )) { while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) break; safe_strcat(stderr_out, buf); } continue; } else { log_messages.printf( SchedMessages::NORMAL, "RESULT::parse_from_client(): unrecognized: %s\n", buf ); } } return ERR_XML_PARSE; } // TODO: put the benchmark errors into the DB // int HOST::parse(FILE* fin) { char buf[256]; int p_fpop_err, p_iop_err, p_membw_err; while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_int(buf, "", timezone)) continue; else if (parse_str(buf, "", domain_name, sizeof(domain_name))) continue; else if (parse_str(buf, "", serialnum, sizeof(serialnum))) continue; else if (parse_str(buf, "", last_ip_addr, sizeof(last_ip_addr))) continue; else if (parse_int(buf, "", p_ncpus)) continue; else if (parse_str(buf, "", p_vendor, sizeof(p_vendor))) continue; else if (parse_str(buf, "", p_model, sizeof(p_model))) continue; else if (parse_double(buf, "", p_fpops)) continue; else if (parse_double(buf, "", p_iops)) continue; else if (parse_double(buf, "", p_membw)) continue; else if (parse_int(buf, "", p_fpop_err)) continue; else if (parse_int(buf, "", p_iop_err)) continue; else if (parse_int(buf, "", p_membw_err)) continue; else if (parse_double(buf, "", p_calculated)) continue; else if (parse_str(buf, "", os_name, sizeof(os_name))) continue; else if (parse_str(buf, "", os_version, sizeof(os_version))) continue; else if (parse_double(buf, "", m_nbytes)) continue; else if (parse_double(buf, "", m_cache)) continue; else if (parse_double(buf, "", m_swap)) continue; else if (parse_double(buf, "", d_total)) continue; else if (parse_double(buf, "", d_free)) continue; else if (parse_double(buf, "", n_bwup)) continue; else if (parse_double(buf, "", n_bwdown)) continue; else { log_messages.printf(SchedMessages::NORMAL, "HOST::parse(): unrecognized: %s\n", buf); } } return ERR_XML_PARSE; } int HOST::parse_time_stats(FILE* fin) { char buf[256]; while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_double(buf, "", on_frac)) continue; else if (parse_double(buf, "", connected_frac)) continue; else if (parse_double(buf, "", active_frac)) continue; else { log_messages.printf( SchedMessages::NORMAL, "HOST::parse_time_stats(): unrecognized: %s\n", buf ); } } return ERR_XML_PARSE; } int HOST::parse_net_stats(FILE* fin) { char buf[256]; while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_double(buf, "", n_bwup)) continue; else if (parse_double(buf, "", n_bwdown)) continue; else { log_messages.printf( SchedMessages::NORMAL, "HOST::parse_net_stats(): unrecognized: %s\n", buf ); } } return ERR_XML_PARSE; } void GLOBAL_PREFS::parse(char* buf) { disk_max_used_gb = 0; disk_max_used_pct = 0; disk_min_free_gb = 0; parse_double(buf, "", disk_max_used_gb); parse_double(buf, "", disk_max_used_pct); parse_double(buf, "", disk_min_free_gb); }