diff --git a/checkin_notes b/checkin_notes index 340f54005f..8143a6baa5 100644 --- a/checkin_notes +++ b/checkin_notes @@ -4826,3 +4826,24 @@ Rom 10 Aug 2011 CE_IsDialogBanner.bmp CE_IsDialogBitmap.bmp CE_Splash.bmp + +David 10 Aug 2011 + - Improve interface of XML_PARSER. + Add parsed_tag and is_tag to the class, + so that parsing functions don't need to declare them + and pass them around. + - Complete the task of using XML_PARSER as the argument + to all parsing functions. + (Internally, many of these functions still use the old XML parser; + that's the next step.) + + db/ + boinc_db.cpp,h + sched/ + various + tools/ + backend_lib.cpp + lib/ + various + client/ + various diff --git a/client/acct_mgr.cpp b/client/acct_mgr.cpp index 2022e6c18b..4c44f9b181 100644 --- a/client/acct_mgr.cpp +++ b/client/acct_mgr.cpp @@ -211,8 +211,8 @@ void AM_ACCOUNT::handle_no_rsc(const char* name, bool value) { } int AM_ACCOUNT::parse(XML_PARSER& xp) { - char tag[256], buf[256]; - bool is_tag, btemp; + char buf[256]; + bool btemp; int retval; double dtemp; @@ -228,54 +228,54 @@ int AM_ACCOUNT::parse(XML_PARSER& xp) { authenticator = ""; resource_share.init(); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { if (log_flags.unparsed_xml) { msg_printf(0, MSG_INFO, "[unparsed_xml] AM_ACCOUNT::parse: unexpected text %s", - tag + xp.parsed_tag ); } continue; } - if (!strcmp(tag, "/account")) { + if (xp.match_tag("/account")) { if (url.length()) return 0; return ERR_XML_PARSE; } - if (xp.parse_string(tag, "url", url)) continue; - if (!strcmp(tag, "url_signature")) { + if (xp.parse_string("url", url)) continue; + if (xp.match_tag("url_signature")) { retval = xp.element_contents("", url_signature, sizeof(url_signature)); if (retval) return retval; strcat(url_signature, "\n"); continue; } - if (xp.parse_string(tag, "authenticator", authenticator)) continue; - if (xp.parse_bool(tag, "detach", detach)) continue; - if (xp.parse_bool(tag, "update", update)) continue; - if (xp.parse_bool(tag, "no_cpu", btemp)) { + if (xp.parse_string("authenticator", authenticator)) continue; + if (xp.parse_bool("detach", detach)) continue; + if (xp.parse_bool("update", update)) continue; + if (xp.parse_bool("no_cpu", btemp)) { handle_no_rsc("CPU", btemp); continue; } - if (xp.parse_bool(tag, "no_cuda", btemp)) { + if (xp.parse_bool("no_cuda", btemp)) { handle_no_rsc("NVIDIA", btemp); continue; } - if (xp.parse_bool(tag, "no_ati", btemp)) { + if (xp.parse_bool("no_ati", btemp)) { handle_no_rsc("ATI", btemp); continue; } - if (xp.parse_str(tag, "no_rsc", buf, sizeof(buf))) { + if (xp.parse_str("no_rsc", buf, sizeof(buf))) { handle_no_rsc(buf, true); } - if (xp.parse_bool(tag, "dont_request_more_work", btemp)) { + if (xp.parse_bool("dont_request_more_work", btemp)) { dont_request_more_work.set(btemp); continue; } - if (xp.parse_bool(tag, "detach_when_done", btemp)) { + if (xp.parse_bool("detach_when_done", btemp)) { detach_when_done.set(btemp); continue; } - if (xp.parse_double(tag, "resource_share", dtemp)) { + if (xp.parse_double("resource_share", dtemp)) { if (dtemp >= 0) { resource_share.set(dtemp); } else { @@ -285,27 +285,25 @@ int AM_ACCOUNT::parse(XML_PARSER& xp) { } continue; } - if (xp.parse_bool(tag, "suspend", btemp)) { + if (xp.parse_bool("suspend", btemp)) { suspend.set(btemp); continue; } - if (xp.parse_bool(tag, "abort_not_started", btemp)) { + if (xp.parse_bool("abort_not_started", btemp)) { abort_not_started.set(btemp); continue; } if (log_flags.unparsed_xml) { msg_printf(NULL, MSG_INFO, - "[unparsed_xml] AM_ACCOUNT: unrecognized %s", tag + "[unparsed_xml] AM_ACCOUNT: unrecognized %s", xp.parsed_tag ); } - xp.skip_unexpected(tag, log_flags.unparsed_xml, "AM_ACCOUNT::parse"); + xp.skip_unexpected(log_flags.unparsed_xml, "AM_ACCOUNT::parse"); } return ERR_XML_PARSE; } int ACCT_MGR_OP::parse(FILE* f) { - char tag[1024]; - bool is_tag; string message; int retval; MIOFILE mf; @@ -320,36 +318,36 @@ int ACCT_MGR_OP::parse(FILE* f) { strcpy(ami.opaque, ""); rss_feeds.clear(); if (!xp.parse_start("acct_mgr_reply")) return ERR_XML_PARSE; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { if (log_flags.unparsed_xml) { msg_printf(0, MSG_INFO, "[unparsed_xml] ACCT_MGR_OP::parse: unexpected text %s", - tag + xp.parsed_tag ); } continue; } - if (!strcmp(tag, "/acct_mgr_reply")) return 0; - if (xp.parse_str(tag, "name", ami.project_name, 256)) continue; - if (xp.parse_int(tag, "error_num", error_num)) continue; - if (xp.parse_string(tag, "error", error_str)) continue; - if (xp.parse_double(tag, "repeat_sec", repeat_sec)) continue; - if (xp.parse_string(tag, "message", message)) { + if (xp.match_tag("/acct_mgr_reply")) return 0; + if (xp.parse_str("name", ami.project_name, 256)) continue; + if (xp.parse_int("error_num", error_num)) continue; + if (xp.parse_string("error", error_str)) continue; + if (xp.parse_double("repeat_sec", repeat_sec)) continue; + if (xp.parse_string("message", message)) { msg_printf(NULL, MSG_INFO, "Account manager: %s", message.c_str()); continue; } - if (!strcmp(tag, "opaque")) { + if (xp.match_tag("opaque")) { retval = xp.element_contents("", ami.opaque, sizeof(ami.opaque)); if (retval) return retval; continue; } - if (!strcmp(tag, "signing_key")) { + if (xp.match_tag("signing_key")) { retval = xp.element_contents("", ami.signing_key, sizeof(ami.signing_key)); if (retval) return retval; continue; } - if (!strcmp(tag, "account")) { + if (xp.match_tag("account")) { AM_ACCOUNT account; retval = account.parse(xp); if (retval) { @@ -362,7 +360,7 @@ int ACCT_MGR_OP::parse(FILE* f) { } continue; } - if (!strcmp(tag, "global_preferences")) { + if (xp.match_tag("global_preferences")) { retval = dup_element_contents( f, "", @@ -377,20 +375,21 @@ int ACCT_MGR_OP::parse(FILE* f) { } continue; } - if (xp.parse_str(tag, "host_venue", host_venue, sizeof(host_venue))) { + if (xp.parse_str("host_venue", host_venue, sizeof(host_venue))) { continue; } - if (!strcmp(tag, "rss_feeds")) { + if (xp.match_tag("rss_feeds")) { got_rss_feeds = true; parse_rss_feed_descs(mf, rss_feeds); continue; } if (log_flags.unparsed_xml) { msg_printf(NULL, MSG_INFO, - "[unparsed_xml] ACCT_MGR_OP::parse: unrecognized %s", tag + "[unparsed_xml] ACCT_MGR_OP::parse: unrecognized %s", + xp.parsed_tag ); } - xp.skip_unexpected(tag, log_flags.unparsed_xml, "ACCT_MGR_OP::parse"); + xp.skip_unexpected(log_flags.unparsed_xml, "ACCT_MGR_OP::parse"); } return ERR_XML_PARSE; } @@ -723,8 +722,6 @@ ACCT_MGR_INFO::ACCT_MGR_INFO() { } int ACCT_MGR_INFO::parse_login_file(FILE* p) { - char tag[1024]; - bool is_tag; MIOFILE mf; int retval; @@ -733,35 +730,34 @@ int ACCT_MGR_INFO::parse_login_file(FILE* p) { if (!xp.parse_start("acct_mgr_login")) { // } - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { - printf("unexpected text: %s\n", tag); + while (!xp.get_tag()) { + if (!xp.is_tag) { + printf("unexpected text: %s\n", xp.parsed_tag); continue; } - if (!strcmp(tag, "/acct_mgr_login")) break; - else if (xp.parse_str(tag, "login", login_name, 256)) continue; - else if (xp.parse_str(tag, "password_hash", password_hash, 256)) continue; - else if (xp.parse_str(tag, "previous_host_cpid", previous_host_cpid, sizeof(previous_host_cpid))) continue; - else if (xp.parse_double(tag, "next_rpc_time", next_rpc_time)) continue; - else if (!strcmp(tag, "opaque")) { + if (xp.match_tag("/acct_mgr_login")) break; + else if (xp.parse_str("login", login_name, 256)) continue; + else if (xp.parse_str("password_hash", password_hash, 256)) continue; + else if (xp.parse_str("previous_host_cpid", previous_host_cpid, sizeof(previous_host_cpid))) continue; + else if (xp.parse_double("next_rpc_time", next_rpc_time)) continue; + else if (xp.match_tag("opaque")) { retval = xp.element_contents("", opaque, sizeof(opaque)); continue; } if (log_flags.unparsed_xml) { msg_printf(NULL, MSG_INFO, - "[unparsed_xml] ACCT_MGR_INFO::parse_login: unrecognized %s", tag + "[unparsed_xml] ACCT_MGR_INFO::parse_login: unrecognized %s", + xp.parsed_tag ); } xp.skip_unexpected( - tag, log_flags.unparsed_xml, "ACCT_MGR_INFO::parse_login_file" + log_flags.unparsed_xml, "ACCT_MGR_INFO::parse_login_file" ); } return 0; } int ACCT_MGR_INFO::init() { - char tag[1024]; - bool is_tag; MIOFILE mf; FILE* p; int retval; @@ -774,27 +770,28 @@ int ACCT_MGR_INFO::init() { if (!xp.parse_start("acct_mgr_login")) { // } - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { - printf("unexpected text: %s\n", tag); + while (!xp.get_tag()) { + if (!xp.is_tag) { + printf("unexpected text: %s\n", xp.parsed_tag); continue; } - if (!strcmp(tag, "/acct_mgr")) break; - else if (xp.parse_str(tag, "name", project_name, 256)) continue; - else if (xp.parse_str(tag, "url", master_url, 256)) continue; - else if (xp.parse_bool(tag, "send_gui_rpc_info", send_gui_rpc_info)) continue; - else if (!strcmp(tag, "signing_key")) { + if (xp.match_tag("/acct_mgr")) break; + else if (xp.parse_str("name", project_name, 256)) continue; + else if (xp.parse_str("url", master_url, 256)) continue; + else if (xp.parse_bool("send_gui_rpc_info", send_gui_rpc_info)) continue; + else if (xp.match_tag("signing_key")) { retval = xp.element_contents("", signing_key, sizeof(signing_key)); continue; } - else if (xp.parse_bool(tag, "cookie_required", cookie_required)) continue; - else if (xp.parse_str(tag, "cookie_failure_url", cookie_failure_url, 256)) continue; + else if (xp.parse_bool("cookie_required", cookie_required)) continue; + else if (xp.parse_str("cookie_failure_url", cookie_failure_url, 256)) continue; if (log_flags.unparsed_xml) { msg_printf(NULL, MSG_INFO, - "[unparsed_xml] ACCT_MGR_INFO::init: unrecognized %s", tag + "[unparsed_xml] ACCT_MGR_INFO::init: unrecognized %s", + xp.parsed_tag ); } - xp.skip_unexpected(tag, log_flags.unparsed_xml, "ACCT_MGR_INFO::init"); + xp.skip_unexpected(log_flags.unparsed_xml, "ACCT_MGR_INFO::init"); } fclose(p); diff --git a/client/client_types.cpp b/client/client_types.cpp index cf2e865b5c..8d249709dc 100644 --- a/client/client_types.cpp +++ b/client/client_types.cpp @@ -946,7 +946,7 @@ int FILE_INFO::parse(XML_PARSER& xp) { int retval; MIOFILE& in = *(xp.f); - while (in.fgets(buf, 256)) { + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "") || match_tag(buf, "")) { if (!strlen(name)) return ERR_BAD_FILENAME; if (strstr(name, "..")) return ERR_BAD_FILENAME; diff --git a/client/cs_notice.cpp b/client/cs_notice.cpp index b0e6aacd77..c50b919fc5 100644 --- a/client/cs_notice.cpp +++ b/client/cs_notice.cpp @@ -61,15 +61,13 @@ static void project_feed_list_file_name(PROJ_AM* p, char* buf) { // parse feed descs from scheduler reply or feed list file // int parse_rss_feed_descs(MIOFILE& fin, vector& feeds) { - char tag[256]; - bool is_tag; XML_PARSER xp(&fin); int retval; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/rss_feeds")) return 0; - if (!strcmp(tag, "rss_feed")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("/rss_feeds")) return 0; + if (xp.match_tag("rss_feed")) { RSS_FEED rf; retval = rf.parse_desc(xp); if (retval) { @@ -213,18 +211,17 @@ static int parse_rss_time(char* buf) { ///////////// NOTICE //////////////// int NOTICE::parse_rss(XML_PARSER& xp) { - char tag[1024], buf[256]; - bool is_tag; + char buf[256]; clear(); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/item")) return 0; - if (xp.parse_str(tag, "title", title, sizeof(title))) continue; - if (xp.parse_str(tag, "link", link, sizeof(link))) continue; - if (xp.parse_str(tag, "guid", guid, sizeof(guid))) continue; - if (xp.parse_string(tag, "description", description)) continue; - if (xp.parse_str(tag, "pubDate", buf, sizeof(buf))) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("/item")) return 0; + if (xp.parse_str("title", title, sizeof(title))) continue; + if (xp.parse_str("link", link, sizeof(link))) continue; + if (xp.parse_str("guid", guid, sizeof(guid))) continue; + if (xp.parse_string("description", description)) continue; + if (xp.parse_str("pubDate", buf, sizeof(buf))) { create_time = parse_rss_time(buf); continue; } @@ -413,9 +410,6 @@ bool NOTICES::append(NOTICE& n) { // insert items in NOTICES // int NOTICES::read_archive_file(const char* path, RSS_FEED* rfp) { - char tag[256]; - bool is_tag; - FILE* f = fopen(path, "r"); if (!f) { if (log_flags.notice_debug) { @@ -428,13 +422,13 @@ int NOTICES::read_archive_file(const char* path, RSS_FEED* rfp) { MIOFILE fin; fin.init_file(f); XML_PARSER xp(&fin); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/notices")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("/notices")) { fclose(f); return 0; } - if (!strcmp(tag, "notice")) { + if (xp.match_tag("notice")) { NOTICE n; int retval = n.parse(xp); if (retval) { @@ -577,14 +571,12 @@ int RSS_FEED::read_archive_file() { // parse a feed descriptor (in scheduler reply or feed list file) // int RSS_FEED::parse_desc(XML_PARSER& xp) { - char tag[256]; - bool is_tag; strcpy(url, ""); poll_interval = 0; next_poll_time = 0; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/rss_feed")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("/rss_feed")) { if (!poll_interval || !strlen(url)) { if (log_flags.notice_debug) { msg_printf(0, MSG_INFO, @@ -598,9 +590,9 @@ int RSS_FEED::parse_desc(XML_PARSER& xp) { if (p) *p = 0; return 0; } - if (xp.parse_str(tag, "url", url, sizeof(url))) continue; - if (xp.parse_double(tag, "poll_interval", poll_interval)) continue; - if (xp.parse_double(tag, "next_poll_time", next_poll_time)) continue; + if (xp.parse_str("url", url, sizeof(url))) continue; + if (xp.parse_double("poll_interval", poll_interval)) continue; + if (xp.parse_double("next_poll_time", next_poll_time)) continue; } return ERR_XML_PARSE; } @@ -625,8 +617,6 @@ static inline bool create_time_asc(NOTICE n1, NOTICE n2) { // parse the actual RSS feed. // int RSS_FEED::parse_items(XML_PARSER& xp, int& nitems) { - char tag[256]; - bool is_tag; nitems = 0; int ntotal = 0, nerror = 0; int retval, func_ret = ERR_XML_PARSE; @@ -634,9 +624,9 @@ int RSS_FEED::parse_items(XML_PARSER& xp, int& nitems) { notices.clear_keep(); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/rss")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("/rss")) { if (log_flags.notice_debug) { msg_printf(0, MSG_INFO, "[notice] parsed RSS feed: total %d error %d added %d", @@ -646,7 +636,7 @@ int RSS_FEED::parse_items(XML_PARSER& xp, int& nitems) { func_ret = 0; break; } - if (!strcmp(tag, "item")) { + if (xp.match_tag("item")) { NOTICE n; ntotal++; retval = n.parse_rss(xp); @@ -668,7 +658,7 @@ int RSS_FEED::parse_items(XML_PARSER& xp, int& nitems) { } continue; } - if (xp.parse_int(tag, "error_num", retval)) { + if (xp.parse_int("error_num", retval)) { if (log_flags.notice_debug) { msg_printf(0,MSG_INFO, "[notice] RSS fetch returned error %d (%s)", diff --git a/client/log_flags.cpp b/client/log_flags.cpp index 93834d2c86..58ba2091ea 100644 --- a/client/log_flags.cpp +++ b/client/log_flags.cpp @@ -177,8 +177,7 @@ void CONFIG::show() { } int CONFIG::parse_options_client(XML_PARSER& xp) { - char tag[1024], path[256]; - bool is_tag; + char path[256]; string s; int n, retval; @@ -193,35 +192,35 @@ int CONFIG::parse_options_client(XML_PARSER& xp) { ignore_nvidia_dev.clear(); ignore_ati_dev.clear(); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { msg_printf_notice(NULL, false, "http://boinc.berkeley.edu/manager_links.php?target=notice&controlid=config", "%s: %s", _("Unexpected text in cc_config.xml"), - tag + xp.parsed_tag ); continue; } - if (!strcmp(tag, "/options")) { + if (xp.match_tag("/options")) { return 0; } - if (xp.parse_bool(tag, "abort_jobs_on_exit", abort_jobs_on_exit)) continue; - if (xp.parse_bool(tag, "allow_multiple_clients", allow_multiple_clients)) continue; - if (xp.parse_bool(tag, "allow_remote_gui_rpc", allow_remote_gui_rpc)) continue; - if (xp.parse_string(tag, "alt_platform", s)) { + if (xp.parse_bool("abort_jobs_on_exit", abort_jobs_on_exit)) continue; + if (xp.parse_bool("allow_multiple_clients", allow_multiple_clients)) continue; + if (xp.parse_bool("allow_remote_gui_rpc", allow_remote_gui_rpc)) continue; + if (xp.parse_string("alt_platform", s)) { alt_platforms.push_back(s); continue; } - if (xp.parse_string(tag, "client_download_url", client_download_url)) { + if (xp.parse_string("client_download_url", client_download_url)) { downcase_string(client_download_url); continue; } - if (xp.parse_string(tag, "client_version_check_url", client_version_check_url)) { + if (xp.parse_string("client_version_check_url", client_version_check_url)) { downcase_string(client_version_check_url); continue; } - if (!strcmp(tag, "coproc")) { + if (xp.match_tag("coproc")) { COPROC c; retval = c.parse(xp); if (retval) { @@ -237,101 +236,99 @@ int CONFIG::parse_options_client(XML_PARSER& xp) { } continue; } - if (xp.parse_str(tag, "data_dir", path, sizeof(path))) { + if (xp.parse_str("data_dir", path, sizeof(path))) { if (chdir(path)) { perror("chdir"); exit(1); } continue; } - if (xp.parse_bool(tag, "disallow_attach", disallow_attach)) continue; - if (xp.parse_bool(tag, "dont_check_file_sizes", dont_check_file_sizes)) continue; - if (xp.parse_bool(tag, "dont_contact_ref_site", dont_contact_ref_site)) continue; - if (xp.parse_string(tag, "exclusive_app", s)) { + if (xp.parse_bool("disallow_attach", disallow_attach)) continue; + if (xp.parse_bool("dont_check_file_sizes", dont_check_file_sizes)) continue; + if (xp.parse_bool("dont_contact_ref_site", dont_contact_ref_site)) continue; + if (xp.parse_string("exclusive_app", s)) { if (!strstr(s.c_str(), "boinc")) { exclusive_apps.push_back(s); } continue; } - if (xp.parse_string(tag, "exclusive_gpu_app", s)) { + if (xp.parse_string("exclusive_gpu_app", s)) { if (!strstr(s.c_str(), "boinc")) { exclusive_gpu_apps.push_back(s); } continue; } - if (xp.parse_bool(tag, "exit_after_finish", exit_after_finish)) continue; - if (xp.parse_bool(tag, "exit_when_idle", exit_when_idle)) { + if (xp.parse_bool("exit_after_finish", exit_after_finish)) continue; + if (xp.parse_bool("exit_when_idle", exit_when_idle)) { if (exit_when_idle) { report_results_immediately = true; } continue; } - if (xp.parse_bool(tag, "fetch_minimal_work", fetch_minimal_work)) continue; - if (xp.parse_string(tag, "force_auth", force_auth)) { + if (xp.parse_bool("fetch_minimal_work", fetch_minimal_work)) continue; + if (xp.parse_string("force_auth", force_auth)) { downcase_string(force_auth); continue; } - if (xp.parse_bool(tag, "http_1_0", http_1_0)) continue; - if (xp.parse_int(tag, "ignore_cuda_dev", n)||xp.parse_int(tag, "ignore_nvidia_dev", n)) { + if (xp.parse_bool("http_1_0", http_1_0)) continue; + if (xp.parse_int("ignore_cuda_dev", n)||xp.parse_int("ignore_nvidia_dev", n)) { ignore_nvidia_dev.push_back(n); continue; } - if (xp.parse_int(tag, "ignore_ati_dev", n)) { + if (xp.parse_int("ignore_ati_dev", n)) { ignore_ati_dev.push_back(n); continue; } - if (xp.parse_int(tag, "max_file_xfers", max_file_xfers)) continue; - if (xp.parse_int(tag, "max_file_xfers_per_project", max_file_xfers_per_project)) continue; - if (xp.parse_int(tag, "max_stderr_file_size", max_stderr_file_size)) continue; - if (xp.parse_int(tag, "max_stdout_file_size", max_stdout_file_size)) continue; - if (xp.parse_int(tag, "max_tasks_reported", max_tasks_reported)) continue; - if (xp.parse_int(tag, "ncpus", ncpus)) continue; - if (xp.parse_string(tag, "network_test_url", network_test_url)) { + if (xp.parse_int("max_file_xfers", max_file_xfers)) continue; + if (xp.parse_int("max_file_xfers_per_project", max_file_xfers_per_project)) continue; + if (xp.parse_int("max_stderr_file_size", max_stderr_file_size)) continue; + if (xp.parse_int("max_stdout_file_size", max_stdout_file_size)) continue; + if (xp.parse_int("max_tasks_reported", max_tasks_reported)) continue; + if (xp.parse_int("ncpus", ncpus)) continue; + if (xp.parse_string("network_test_url", network_test_url)) { downcase_string(network_test_url); continue; } - if (xp.parse_bool(tag, "no_alt_platform", no_alt_platform)) continue; - if (xp.parse_bool(tag, "no_gpus", no_gpus)) continue; - if (xp.parse_bool(tag, "no_info_fetch", no_info_fetch)) continue; - if (xp.parse_bool(tag, "no_priority_change", no_priority_change)) continue; - if (xp.parse_bool(tag, "os_random_only", os_random_only)) continue; + if (xp.parse_bool("no_alt_platform", no_alt_platform)) continue; + if (xp.parse_bool("no_gpus", no_gpus)) continue; + if (xp.parse_bool("no_info_fetch", no_info_fetch)) continue; + if (xp.parse_bool("no_priority_change", no_priority_change)) continue; + if (xp.parse_bool("os_random_only", os_random_only)) continue; #ifndef SIM - if (!strcmp(tag, "proxy_info")) { + if (xp.match_tag("proxy_info")) { retval = config_proxy_info.parse_config(xp); if (retval) return retval; continue; } #endif - if (xp.parse_bool(tag, "report_results_immediately", report_results_immediately)) continue; - if (xp.parse_bool(tag, "run_apps_manually", run_apps_manually)) continue; - if (xp.parse_int(tag, "save_stats_days", save_stats_days)) continue; - if (xp.parse_bool(tag, "simple_gui_only", simple_gui_only)) continue; - if (xp.parse_bool(tag, "skip_cpu_benchmarks", skip_cpu_benchmarks)) continue; - if (xp.parse_double(tag, "start_delay", start_delay)) continue; - if (xp.parse_bool(tag, "stderr_head", stderr_head)) continue; - if (xp.parse_bool(tag, "suppress_net_info", suppress_net_info)) continue; - if (xp.parse_bool(tag, "unsigned_apps_ok", unsigned_apps_ok)) continue; - if (xp.parse_bool(tag, "use_all_gpus", use_all_gpus)) continue; - if (xp.parse_bool(tag, "use_certs", use_certs)) continue; - if (xp.parse_bool(tag, "use_certs_only", use_certs_only)) continue; - if (xp.parse_bool(tag, "zero_debts", zero_debts)) continue; + if (xp.parse_bool("report_results_immediately", report_results_immediately)) continue; + if (xp.parse_bool("run_apps_manually", run_apps_manually)) continue; + if (xp.parse_int("save_stats_days", save_stats_days)) continue; + if (xp.parse_bool("simple_gui_only", simple_gui_only)) continue; + if (xp.parse_bool("skip_cpu_benchmarks", skip_cpu_benchmarks)) continue; + if (xp.parse_double("start_delay", start_delay)) continue; + if (xp.parse_bool("stderr_head", stderr_head)) continue; + if (xp.parse_bool("suppress_net_info", suppress_net_info)) continue; + if (xp.parse_bool("unsigned_apps_ok", unsigned_apps_ok)) continue; + if (xp.parse_bool("use_all_gpus", use_all_gpus)) continue; + if (xp.parse_bool("use_certs", use_certs)) continue; + if (xp.parse_bool("use_certs_only", use_certs_only)) continue; + if (xp.parse_bool("zero_debts", zero_debts)) continue; msg_printf_notice(NULL, false, "http://boinc.berkeley.edu/manager_links.php?target=notice&controlid=config", "%s: <%s>", _("Unrecognized tag in cc_config.xml"), - tag + xp.parsed_tag ); - xp.skip_unexpected(tag, true, "CONFIG::parse_options"); + xp.skip_unexpected(true, "CONFIG::parse_options"); } return ERR_XML_PARSE; } int CONFIG::parse_client(FILE* f) { - char tag[256]; MIOFILE mf; XML_PARSER xp(&mf); - bool is_tag; mf.init_file(f); if (!xp.parse_start("cc_config")) { @@ -342,34 +339,34 @@ int CONFIG::parse_client(FILE* f) { ); return ERR_XML_PARSE; } - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { msg_printf_notice(NULL, false, "http://boinc.berkeley.edu/manager_links.php?target=notice&controlid=config", "%s: %s", _("Unexpected text in cc_config.xml"), - tag + xp.parsed_tag ); continue; } - if (!strcmp(tag, "/cc_config")) return 0; - if (!strcmp(tag, "log_flags")) { + if (xp.match_tag("/cc_config")) return 0; + if (xp.match_tag("log_flags")) { log_flags.parse(xp); continue; } - if (!strcmp(tag, "options")) { + if (xp.match_tag("options")) { parse_options(xp); continue; } - if (!strcmp(tag, "options/")) continue; - if (!strcmp(tag, "log_flags/")) continue; + if (xp.match_tag("options/")) continue; + if (xp.match_tag("log_flags/")) continue; msg_printf_notice(NULL, false, "http://boinc.berkeley.edu/manager_links.php?target=notice&controlid=config", "%s: <%s>", _("Unrecognized tag in cc_config.xml"), - tag + xp.parsed_tag ); - xp.skip_unexpected(tag, true, "CONFIG.parse"); + xp.skip_unexpected(true, "CONFIG.parse"); } msg_printf_notice(NULL, false, "http://boinc.berkeley.edu/manager_links.php?target=notice&controlid=config", diff --git a/client/net_stats.cpp b/client/net_stats.cpp index ae18ffa356..8d1609a7e0 100644 --- a/client/net_stats.cpp +++ b/client/net_stats.cpp @@ -288,14 +288,11 @@ void NET_STATUS::poll() { } int DAILY_XFER::parse(XML_PARSER& xp) { - char tag[1024]; - bool is_tag; - - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!strcmp(tag, "/dx")) return 0; - if (xp.parse_int(tag, "when", when)) continue; - if (xp.parse_double(tag, "up", up)) continue; - if (xp.parse_double(tag, "down", down)) continue; + while (!xp.get_tag()) { + if (xp.match_tag("/dx")) return 0; + if (xp.parse_int("when", when)) continue; + if (xp.parse_double("up", up)) continue; + if (xp.parse_double("down", down)) continue; } return ERR_XML_PARSE; } @@ -346,8 +343,6 @@ void DAILY_XFER_HISTORY::init() { MIOFILE mf; XML_PARSER xp(&mf); mf.init_file(f); - bool is_tag; - char tag[256]; int d = current_day(); @@ -355,9 +350,9 @@ void DAILY_XFER_HISTORY::init() { fclose(f); return; } - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "dx")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("dx")) { DAILY_XFER dx; int retval = dx.parse(xp); if (!retval && d - dx.when < 365) { diff --git a/db/boinc_db.cpp b/db/boinc_db.cpp index eb18a6b7f5..0559ae159b 100644 --- a/db/boinc_db.cpp +++ b/db/boinc_db.cpp @@ -2028,11 +2028,11 @@ void DB_FILESET::db_parse(MYSQL_ROW &r) { strcpy2(name, r[i++]); } -int DB_FILESET::select_by_name(const char* name) { +int DB_FILESET::select_by_name(const char* _name) { char where_clause[MAX_QUERY_LEN] = {0}; // construct where clause and select single record - snprintf(where_clause, MAX_QUERY_LEN, "WHERE name = '%s'", name); + snprintf(where_clause, MAX_QUERY_LEN, "WHERE name = '%s'", _name); return lookup(where_clause); } @@ -2071,7 +2071,7 @@ void DB_SCHED_TRIGGER::db_parse(MYSQL_ROW &r) { int DB_SCHED_TRIGGER::select_unique_by_fileset_name(const char* fileset_name) { char query[MAX_QUERY_LEN]; int retval; - int count = 0; + int nrows = 0; MYSQL_RES* recordset; MYSQL_ROW row; @@ -2101,10 +2101,10 @@ int DB_SCHED_TRIGGER::select_unique_by_fileset_name(const char* fileset_name) { //} // determine number of records, fetch first - count = mysql_num_rows(recordset); + nrows = mysql_num_rows(recordset); row = mysql_fetch_row(recordset); - if (!row || count != 1) { + if (!row || nrows != 1) { // something bad happened if (!row) { // no row returned, due to an error? diff --git a/db/boinc_db.h b/db/boinc_db.h index 26511eca97..f45d5aa9c5 100644 --- a/db/boinc_db.h +++ b/db/boinc_db.h @@ -31,6 +31,7 @@ #include "db_base.h" #include "average.h" +#include "parse.h" extern DB_CONN boinc_db; @@ -333,15 +334,15 @@ struct HOST { // that fail validation // DEPRECATED - // the following not stored in DB - // + // the following not in DB char p_features[1024]; char virtualbox_version[256]; - int parse(FILE*); - int parse_time_stats(FILE*); - int parse_net_stats(FILE*); - int parse_disk_usage(FILE*); + int parse(XML_PARSER&); + int parse_time_stats(XML_PARSER&); + int parse_net_stats(XML_PARSER&); + int parse_disk_usage(XML_PARSER&); + void fix_nans(); void clear(); }; diff --git a/doc/projects.inc b/doc/projects.inc index 41e61a11ad..990ff2857d 100644 --- a/doc/projects.inc +++ b/doc/projects.inc @@ -14,9 +14,9 @@ $cogsci = array( tra("Cognitive science and artifical intelligence"), array( array( - tra("FreeHAL"), + "FreeHAL", "http://www.freehal.net/freehal_at_home/", - tra("private"), + tra("Private"), tra("Artificial intelligence"), tra("Parse and convert semantic nets for use in FreeHAL, an artificial intelligence that uses semantic networks, stemmers, part of speech databases, and part of speech taggers in order to imitate human behavior in conversations.") ), @@ -27,7 +27,7 @@ $biomed = array( tra("Biology and Medicine"), array( array( - tra("POEM@HOME"), + "POEM@HOME", "http://boinc.fzk.de/poem/", tra("University of Karlsruhe (Germany)"), tra("Protein structure prediction"), @@ -35,7 +35,7 @@ $biomed = array( "poem.jpg" ), array( - tra("Docking@Home"), + "Docking@Home", "http://docking.cis.udel.edu/", tra("University of Delaware"), tra("Study of protein - ligand interactions"), @@ -43,7 +43,7 @@ $biomed = array( "docking.png" ), array( - tra("GPUGrid.net"), + "GPUGrid.net", "http://www.gpugrid.net/", tra("Barcelona Biomedical Research Park (PRBB)"), tra("Molecular simulations of proteins"), @@ -51,7 +51,7 @@ $biomed = array( "gpugrid.png" ), array( - tra("Superlink@Technion"), + "Superlink@Technion", "http://cbl-boinc-server2.cs.technion.ac.il/superlinkattechnion/", tra("Technion, Israel"), tra("Genetic linkage analysis"), @@ -59,7 +59,7 @@ $biomed = array( "superlink_logo.gif" ), // array( -// tra("Proteins@Home"), +// "Proteins@Home", // "http://biology.polytechnique.fr/proteinsathome", // tra("Ecole Polytechnique, Paris"), // tra("Protein structure prediction"), @@ -67,7 +67,7 @@ $biomed = array( // "proteinsathome.gif" // ), array( - tra("The Lattice Project"), + "The Lattice Project", "http://boinc.umiacs.umd.edu/", tra("University of Maryland Center for Bioinformatics and Computational Biology"), tra("Life science research"), @@ -75,7 +75,7 @@ $biomed = array( "lattice.gif" ), array( - tra("Malariacontrol.net"), + "Malariacontrol.net", "http://www.malariacontrol.net/", tra("The Swiss Tropical Institute"), tra("Epidemiology"), @@ -83,7 +83,7 @@ $biomed = array( "africaathome.gif" ), // array( -// tra("Tanpaku"), +// "Tanpaku", // "http://issofty17.is.noda.tus.ac.jp/", // tra("Tokyo University of Science"), // tra("Biology"), @@ -91,7 +91,7 @@ $biomed = array( // "tanpaku.jpg" // ), // array( -// tra("Predictor@home"), +// "Predictor@home", // "http://predictor.chem.lsa.umich.edu/", // tra("University of Michigan"), // tra("Biology"), @@ -99,7 +99,7 @@ $biomed = array( // "predictor.jpg" // ), array( - tra("Rosetta@home"), + "Rosetta@home", "http://boinc.bakerlab.org/rosetta/", tra("University of Washington"), tra("Biology"), @@ -107,7 +107,7 @@ $biomed = array( "rosetta_at_home_logo.jpg" ), array( - tra("SIMAP"), + "SIMAP", "http://boincsimap.org/boincsimap/", tra("University of Vienna"), tra("Biology"), @@ -120,21 +120,21 @@ $earth = array( tra("Earth Sciences"), array( // array( -// tra("Quake Catcher Network"), +// "Quake Catcher Network", // "http://qcn.stanford.edu/", // tra("Stanford University"), // tra("Seismology"), // tra("The Quake-Catcher Network is a collaborative initiative for developing the world's largest, low-cost strong-motion seismic network by utilizing sensors in and attached to internet-connected computers.") // ), array( - tra("Virtual Prairie"), + "Virtual Prairie", "http://vcsc.cs.uh.edu/virtual-prairie/", tra("University of Houston"), tra("Study of botanical ecosystems"), tra("Provide ecological guidelines on the design of prairies with the best potential for water purification.") ), array( - tra("Climateprediction.net"), + "Climateprediction.net", "http://climateprediction.net/", tra("Oxford University"), tra("Climate study"), @@ -148,14 +148,14 @@ $astro_phys_chem = array( tra("Astronomy/Physics/Chemistry"), array( array( - tra("eOn"), + "eOn", "http://eon.ices.utexas.edu/eon2/", tra("University of Texas at Austin"), tra("Chemistry"), tra("A common problem in theoretical chemistry, condensed matter physics and materials science is the calculation of the time evolution of an atomic scale system where, for example, chemical reactions and/or diffusion occur. Generally the events of interest are quite rare (many orders of magnitude slower than the vibrational movements of the atoms), and therefore direct simulations, tracking every movement of the atoms, would take thousands of years of computer calculations on the fastest present day computer before a single event of interest can be expected to occur. Our research group is interested in calculating the long time dynamics of systems.") ), array( - tra("Orbit@home"), + "Orbit@home", "http://orbit.psi.edu/oah/", tra("Planetary Science Institute"), tra("Astronomy"), @@ -163,7 +163,7 @@ $astro_phys_chem = array( "http://orbit.psi.edu/" ), array( - tra("Cosmology@Home"), + "Cosmology@Home", "http://www.cosmologyathome.org/", tra("University of Illinois at Urbana-Champaign"), tra("Astronomy"), @@ -171,7 +171,7 @@ $astro_phys_chem = array( "cosmo.jpg" ), array( - tra("Milkyway@home"), + "Milkyway@home", "http://milkyway.cs.rpi.edu/milkyway/", tra("Rensselaer Polytechnic Institute"), tra("Astronomy"), @@ -179,7 +179,7 @@ $astro_phys_chem = array( "mw.png", ), array( - tra("Leiden Classical"), + "Leiden Classical", "http://boinc.gorlaeus.net/", tra("Leiden University, The Netherlands"), tra("Chemistry"), @@ -187,7 +187,7 @@ $astro_phys_chem = array( "leiden_classical.png" ), array( - tra("uFluids@home"), + "uFluids@home", "http://www.ufluids.net/", tra("Purdue University"), tra("Physics/Aeronautics"), @@ -195,7 +195,7 @@ $astro_phys_chem = array( "ufluids.gif" ), array( - tra("Einstein@home"), + "Einstein@home", "http://einstein.phys.uwm.edu/", tra("Univ. of Wisconsin - Milwaukee, Max Planck Institute"), tra("Astrophysics"), @@ -203,7 +203,7 @@ $astro_phys_chem = array( "einstein.jpg" ), array( - tra("LHC@home"), + "LHC@home", "http://lhcathome.cern.ch/lhcathome/", tra("CERN (European Organization for Nuclear Research)"), tra("Physics"), @@ -211,7 +211,7 @@ $astro_phys_chem = array( "lhc.jpg" ), array( - tra("SETI@home"), + "SETI@home", "http://setiathome.berkeley.edu/", tra("University of California, Berkeley"), tra("Astrophysics, astrobiology"), @@ -219,7 +219,7 @@ $astro_phys_chem = array( "seti_logo.png" ), array( - tra("Quantum Monte Carlo at Home"), + "Quantum Monte Carlo at Home", "http://qah.uni-muenster.de/", tra("University of Muenster (Germany)"), tra("Chemistry"), @@ -227,7 +227,7 @@ $astro_phys_chem = array( "logo_oben.jpg" ), array( - tra("Spinhenge@home"), + "Spinhenge@home", "http://spin.fh-bielefeld.de/", tra("Bielefeld University of Applied Sciences"), tra("Chemical engineering and nanotechnology"), @@ -241,7 +241,7 @@ $mixed = array( tra("Multiple applications"), array( array( - tra("CAS@home"), + "CAS@home", "http://casathome.ihep.ac.cn/", tra("Chinese Academy of Sciences"), tra("Physics, biochemistry, and others"), @@ -249,14 +249,14 @@ $mixed = array( "cas_at_home.jpg" ), array( - tra("Yoyo@home"), + "Yoyo@home", "http://www.rechenkraft.net/yoyo/", - tra("private"), + tra("Private"), tra("Mathematics, physics, evolution"), tra("Yoyo@home is an adapter between BOINC and several existing volunteer computing projects: ECM, Muon, Evolution@home, and distributed.net") ), array( - tra("EDGeS@Home"), + "EDGeS@Home", "http://home.edges-grid.eu/home/", tra("MTA-SZTAKI Laboratory of Parallel and Distributed Systems (Hungary)"), tra("European research projects"), @@ -264,7 +264,7 @@ $mixed = array( "logo_edges.png" ), array( - tra("Ibercivis"), + "Ibercivis", "http://registro.ibercivis.es/", tra("Spanish universities and research centers"), tra("Various Spanish research projects"), @@ -272,7 +272,7 @@ $mixed = array( "cabecera2.jpg" ), array( - tra("World Community Grid"), + "World Community Grid", "http://www.worldcommunitygrid.org/", tra("IBM Corporate Community Relations"), tra("Humanitarian research on disease, natural disasters and hunger."), @@ -285,21 +285,29 @@ $math = array( tra("Mathematics, computing, and games"), array( array( - tra("Enigma@Home"), + "DistrRTgen", + "http://boinc.freerainbowtables.com/distrrtgen/", + "Private", + tra("Cryptography"), + "To give the world's security experts the best tools available for detecting weak hashes. This can help them to force developers to use more secure methods of password protection.", + "freerainbowtables_logo.png", + ), + array( + "Enigma@Home", "http://www.enigmaathome.net/", - tra("private"), + tra("Private"), tra("Cryptography"), tra("Attempt to decode 3 original Enigma messages. The signals were intercepted in the North Atlantic in 1942 and are believed to be unbroken.") ), array( - tra("Collatz Conjecture"), + "Collatz Conjecture", "http://boinc.thesonntags.com/collatz/", - tra("private"), + tra("Private"), tra("Mathematics"), tra("Study the Collatz Conjecture, an unsolved conjecture in mathematics"), ), array( - tra("NFS@home"), + "NFS@home", "http://escatter11.fullerton.edu/nfs/", tra("California State University Fullerton"), tra("Factorization of large integers"), @@ -307,7 +315,7 @@ $math = array( "NFS_Logo.jpg" ), array( - tra("VTU@home"), + "VTU@home", "http://boinc.vgtu.lt/vtuathome/", tra("Vilnius Gediminas Technical University and Kaunas University of Technology (Lithuania)"), tra("Software testing"), @@ -315,7 +323,7 @@ $math = array( "vtuathome-white.gif", ), array( - tra("AQUA@home"), + "AQUA@home", "http://aqua.dwavesys.com/", tra("D-Wave Systems, Inc."), tra("Quantum computing"), @@ -323,7 +331,7 @@ $math = array( "logo_dwave2.png" ), // array( -// tra("SHA-1 Collision Search Graz"), +// "SHA-1 Collision Search Graz", // "http://boinc.iaik.tugraz.at/sha1_coll_search/", // tra("Graz University of Technology (Austria)"), // tra("Cryptography"), @@ -331,7 +339,7 @@ $math = array( // "LogoKryptoGroup_klein.jpg" // ), array( - tra("ABC@home"), + "ABC@home", "http://abcathome.com/", tra("Mathematical Institute of Leiden University / Kennislink"), tra("Mathematics"), @@ -339,7 +347,7 @@ $math = array( "" ), array( - tra("PrimeGrid"), + "PrimeGrid", "http://www.primegrid.com/", tra("Private"), tra("Cryptography"), @@ -347,7 +355,7 @@ $math = array( "primegrid_logo.png" ), array( - tra("primaboinca"), + "primaboinca", "http://www.primaboinca.com/", tra("Hochschule RheinMain University of Applied Sciences"), tra("Mathematics"), @@ -355,7 +363,7 @@ $math = array( "logo_primaboinca.gif" ), array( - tra("SZTAKI Desktop Grid"), + "SZTAKI Desktop Grid", "http://szdg.lpds.sztaki.hu/szdg/", tra("MTA-SZTAKI Laboratory of Parallel and Distributed Systems (Hungary)"), tra("Mathematics"), @@ -363,7 +371,7 @@ $math = array( "szdg1_small.jpg" ), // array( -// tra("Riesel Sieve"), +// "Riesel Sieve", // "http://boinc.rieselsieve.com/", // tra("Riesel Sieve community"), // tra("Mathematics"), @@ -371,7 +379,7 @@ $math = array( // "" // ), // array( -// tra("Rectilinear Crossing Number"), +// "Rectilinear Crossing Number", // "http://dist.ist.tugraz.at/cape5/", // tra("Graz University of Technology (Austria)"), // tra("Mathematics"), @@ -379,7 +387,7 @@ $math = array( // "" // ), array( - tra("Chess960@home"), + "Chess960@home", "http://www.chess960athome.org/alpha/", tra("Chess-960.org"), tra("Game-playing"), @@ -387,7 +395,7 @@ $math = array( "chess960athome.jpg" ), // array( -// tra("NQueens@home"), +// "NQueens@home", // "http://nqueens.ing.udec.cl/", // tra("Universidad de ConcepciĆ³n, Chile"), // tra("Mathematics"), diff --git a/lib/app_ipc.cpp b/lib/app_ipc.cpp index 59edefeda7..181e41f6c8 100644 --- a/lib/app_ipc.cpp +++ b/lib/app_ipc.cpp @@ -271,9 +271,9 @@ void APP_INIT_DATA::clear() { } int parse_init_data_file(FILE* f, APP_INIT_DATA& ai) { - char tag[1024], buf[256]; + char buf[256]; int retval; - bool flag, is_tag; + bool flag; MIOFILE mf; mf.init_file(f); @@ -292,76 +292,78 @@ int parse_init_data_file(FILE* f, APP_INIT_DATA& ai) { ai.fraction_done_start = 0; ai.fraction_done_end = 1; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { - fprintf(stderr, "unexpected text in init_data.xml: %s\n", tag); + while (!xp.get_tag()) { + if (!xp.is_tag) { + fprintf(stderr, + "unexpected text in init_data.xml: %s\n", xp.parsed_tag + ); continue; } - if (!strcmp(tag, "/app_init_data")) return 0; - if (!strcmp(tag, "project_preferences")) { + if (xp.match_tag("/app_init_data")) return 0; + if (xp.match_tag("project_preferences")) { retval = dup_element(f, "project_preferences", &ai.project_preferences); if (retval) return retval; continue; } - if (!strcmp(tag, "global_preferences")) { + if (xp.match_tag("global_preferences")) { GLOBAL_PREFS_MASK mask; retval = ai.global_prefs.parse(xp, "", flag, mask); if (retval) return retval; continue; } - if (!strcmp(tag, "host_info")) { + if (xp.match_tag("host_info")) { ai.host_info.parse(xp); continue; } - if (!strcmp(tag, "proxy_info")) { + if (xp.match_tag("proxy_info")) { ai.proxy_info.parse(xp); continue; } - if (xp.parse_int(tag, "major_version", ai.major_version)) continue; - if (xp.parse_int(tag, "minor_version", ai.minor_version)) continue; - if (xp.parse_int(tag, "release", ai.release)) continue; - if (xp.parse_int(tag, "app_version", ai.app_version)) continue; - if (xp.parse_str(tag, "app_name", ai.app_name, sizeof(ai.app_name))) continue; - if (xp.parse_str(tag, "symstore", ai.symstore, sizeof(ai.symstore))) continue; - if (xp.parse_str(tag, "acct_mgr_url", ai.acct_mgr_url, sizeof(ai.acct_mgr_url))) continue; - if (xp.parse_int(tag, "userid", ai.userid)) continue; - if (xp.parse_int(tag, "teamid", ai.teamid)) continue; - if (xp.parse_int(tag, "hostid", ai.hostid)) continue; - if (xp.parse_str(tag, "user_name", buf, sizeof(buf))) { + if (xp.parse_int("major_version", ai.major_version)) continue; + if (xp.parse_int("minor_version", ai.minor_version)) continue; + if (xp.parse_int("release", ai.release)) continue; + if (xp.parse_int("app_version", ai.app_version)) continue; + if (xp.parse_str("app_name", ai.app_name, sizeof(ai.app_name))) continue; + if (xp.parse_str("symstore", ai.symstore, sizeof(ai.symstore))) continue; + if (xp.parse_str("acct_mgr_url", ai.acct_mgr_url, sizeof(ai.acct_mgr_url))) continue; + if (xp.parse_int("userid", ai.userid)) continue; + if (xp.parse_int("teamid", ai.teamid)) continue; + if (xp.parse_int("hostid", ai.hostid)) continue; + if (xp.parse_str("user_name", buf, sizeof(buf))) { xml_unescape(buf, ai.user_name, sizeof(ai.user_name)); continue; } - if (xp.parse_str(tag, "team_name", buf, sizeof(buf))) { + if (xp.parse_str("team_name", buf, sizeof(buf))) { xml_unescape(buf, ai.team_name, sizeof(ai.team_name)); continue; } - if (xp.parse_str(tag, "project_dir", ai.project_dir, sizeof(ai.project_dir))) continue; - if (xp.parse_str(tag, "boinc_dir", ai.boinc_dir, sizeof(ai.boinc_dir))) continue; - if (xp.parse_str(tag, "authenticator", ai.authenticator, sizeof(ai.authenticator))) continue; - if (xp.parse_str(tag, "wu_name", ai.wu_name, sizeof(ai.wu_name))) continue; - if (xp.parse_str(tag, "result_name", ai.result_name, sizeof(ai.result_name))) continue; + if (xp.parse_str("project_dir", ai.project_dir, sizeof(ai.project_dir))) continue; + if (xp.parse_str("boinc_dir", ai.boinc_dir, sizeof(ai.boinc_dir))) continue; + if (xp.parse_str("authenticator", ai.authenticator, sizeof(ai.authenticator))) continue; + if (xp.parse_str("wu_name", ai.wu_name, sizeof(ai.wu_name))) continue; + if (xp.parse_str("result_name", ai.result_name, sizeof(ai.result_name))) continue; #ifdef _WIN32 - if (xp.parse_str(tag, "comm_obj_name", ai.shmem_seg_name, sizeof(ai.shmem_seg_name))) continue; + if (xp.parse_str("comm_obj_name", ai.shmem_seg_name, sizeof(ai.shmem_seg_name))) continue; #else - if (xp.parse_int(tag, "shm_key", ai.shmem_seg_name)) continue; + if (xp.parse_int("shm_key", ai.shmem_seg_name)) continue; #endif - if (xp.parse_int(tag, "slot", ai.slot)) continue; - if (xp.parse_double(tag, "user_total_credit", ai.user_total_credit)) continue; - if (xp.parse_double(tag, "user_expavg_credit", ai.user_expavg_credit)) continue; - if (xp.parse_double(tag, "host_total_credit", ai.host_total_credit)) continue; - if (xp.parse_double(tag, "host_expavg_credit", ai.host_expavg_credit)) continue; - if (xp.parse_double(tag, "resource_share_fraction", ai.resource_share_fraction)) continue; - if (xp.parse_double(tag, "rsc_fpops_est", ai.rsc_fpops_est)) continue; - if (xp.parse_double(tag, "rsc_fpops_bound", ai.rsc_fpops_bound)) continue; - if (xp.parse_double(tag, "rsc_memory_bound", ai.rsc_memory_bound)) continue; - if (xp.parse_double(tag, "rsc_disk_bound", ai.rsc_disk_bound)) continue; - if (xp.parse_double(tag, "computation_deadline", ai.computation_deadline)) continue; - if (xp.parse_double(tag, "wu_cpu_time", ai.wu_cpu_time)) continue; - if (xp.parse_double(tag, "starting_elapsed_time", ai.starting_elapsed_time)) continue; - if (xp.parse_double(tag, "checkpoint_period", ai.checkpoint_period)) continue; - if (xp.parse_double(tag, "fraction_done_start", ai.fraction_done_start)) continue; - if (xp.parse_double(tag, "fraction_done_end", ai.fraction_done_end)) continue; - xp.skip_unexpected(tag, false, "parse_init_data_file"); + if (xp.parse_int("slot", ai.slot)) continue; + if (xp.parse_double("user_total_credit", ai.user_total_credit)) continue; + if (xp.parse_double("user_expavg_credit", ai.user_expavg_credit)) continue; + if (xp.parse_double("host_total_credit", ai.host_total_credit)) continue; + if (xp.parse_double("host_expavg_credit", ai.host_expavg_credit)) continue; + if (xp.parse_double("resource_share_fraction", ai.resource_share_fraction)) continue; + if (xp.parse_double("rsc_fpops_est", ai.rsc_fpops_est)) continue; + if (xp.parse_double("rsc_fpops_bound", ai.rsc_fpops_bound)) continue; + if (xp.parse_double("rsc_memory_bound", ai.rsc_memory_bound)) continue; + if (xp.parse_double("rsc_disk_bound", ai.rsc_disk_bound)) continue; + if (xp.parse_double("computation_deadline", ai.computation_deadline)) continue; + if (xp.parse_double("wu_cpu_time", ai.wu_cpu_time)) continue; + if (xp.parse_double("starting_elapsed_time", ai.starting_elapsed_time)) continue; + if (xp.parse_double("checkpoint_period", ai.checkpoint_period)) continue; + if (xp.parse_double("fraction_done_start", ai.fraction_done_start)) continue; + if (xp.parse_double("fraction_done_end", ai.fraction_done_end)) continue; + xp.skip_unexpected(false, "parse_init_data_file"); } fprintf(stderr, "parse_init_data_file: no end tag\n"); return ERR_XML_PARSE; diff --git a/lib/cc_config.cpp b/lib/cc_config.cpp index a157123dc6..fdbe8d7a94 100644 --- a/lib/cc_config.cpp +++ b/lib/cc_config.cpp @@ -52,50 +52,47 @@ void LOG_FLAGS::init() { // Parse log flag preferences // int LOG_FLAGS::parse(XML_PARSER& xp) { - char tag[1024]; - bool is_tag; - - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { continue; } - if (!strcmp(tag, "/log_flags")) return 0; - if (xp.parse_bool(tag, "file_xfer", file_xfer)) continue; - if (xp.parse_bool(tag, "sched_ops", sched_ops)) continue; - if (xp.parse_bool(tag, "task", task)) continue; + if (xp.match_tag("/log_flags")) return 0; + if (xp.parse_bool("file_xfer", file_xfer)) continue; + if (xp.parse_bool("sched_ops", sched_ops)) continue; + if (xp.parse_bool("task", task)) continue; - if (xp.parse_bool(tag, "app_msg_receive", app_msg_receive)) continue; - if (xp.parse_bool(tag, "app_msg_send", app_msg_send)) continue; - if (xp.parse_bool(tag, "benchmark_debug", benchmark_debug)) continue; - if (xp.parse_bool(tag, "checkpoint_debug", checkpoint_debug)) continue; - if (xp.parse_bool(tag, "coproc_debug", coproc_debug)) continue; - if (xp.parse_bool(tag, "cpu_sched", cpu_sched)) continue; - if (xp.parse_bool(tag, "cpu_sched_debug", cpu_sched_debug)) continue; - if (xp.parse_bool(tag, "cpu_sched_status", cpu_sched_status)) continue; - if (xp.parse_bool(tag, "dcf_debug", dcf_debug)) continue; - if (xp.parse_bool(tag, "debt_debug", debt_debug)) continue; - if (xp.parse_bool(tag, "std_debug", std_debug)) continue; - if (xp.parse_bool(tag, "file_xfer_debug", file_xfer_debug)) continue; - if (xp.parse_bool(tag, "gui_rpc_debug", gui_rpc_debug)) continue; - if (xp.parse_bool(tag, "heartbeat_debug", heartbeat_debug)) continue; - if (xp.parse_bool(tag, "http_debug", http_debug)) continue; - if (xp.parse_bool(tag, "http_xfer_debug", http_xfer_debug)) continue; - if (xp.parse_bool(tag, "mem_usage_debug", mem_usage_debug)) continue; - if (xp.parse_bool(tag, "network_status_debug", network_status_debug)) continue; - if (xp.parse_bool(tag, "poll_debug", poll_debug)) continue; - if (xp.parse_bool(tag, "proxy_debug", proxy_debug)) continue; - if (xp.parse_bool(tag, "rr_simulation", rr_simulation)) continue; - if (xp.parse_bool(tag, "sched_op_debug", sched_op_debug)) continue; - if (xp.parse_bool(tag, "scrsave_debug", scrsave_debug)) continue; - if (xp.parse_bool(tag, "slot_debug", slot_debug)) continue; - if (xp.parse_bool(tag, "state_debug", state_debug)) continue; - if (xp.parse_bool(tag, "statefile_debug", statefile_debug)) continue; - if (xp.parse_bool(tag, "task_debug", task_debug)) continue; - if (xp.parse_bool(tag, "time_debug", time_debug)) continue; - if (xp.parse_bool(tag, "unparsed_xml", unparsed_xml)) continue; - if (xp.parse_bool(tag, "work_fetch_debug", work_fetch_debug)) continue; - if (xp.parse_bool(tag, "notice_debug", notice_debug)) continue; - xp.skip_unexpected(tag, true, "LOG_FLAGS::parse"); + if (xp.parse_bool("app_msg_receive", app_msg_receive)) continue; + if (xp.parse_bool("app_msg_send", app_msg_send)) continue; + if (xp.parse_bool("benchmark_debug", benchmark_debug)) continue; + if (xp.parse_bool("checkpoint_debug", checkpoint_debug)) continue; + if (xp.parse_bool("coproc_debug", coproc_debug)) continue; + if (xp.parse_bool("cpu_sched", cpu_sched)) continue; + if (xp.parse_bool("cpu_sched_debug", cpu_sched_debug)) continue; + if (xp.parse_bool("cpu_sched_status", cpu_sched_status)) continue; + if (xp.parse_bool("dcf_debug", dcf_debug)) continue; + if (xp.parse_bool("debt_debug", debt_debug)) continue; + if (xp.parse_bool("std_debug", std_debug)) continue; + if (xp.parse_bool("file_xfer_debug", file_xfer_debug)) continue; + if (xp.parse_bool("gui_rpc_debug", gui_rpc_debug)) continue; + if (xp.parse_bool("heartbeat_debug", heartbeat_debug)) continue; + if (xp.parse_bool("http_debug", http_debug)) continue; + if (xp.parse_bool("http_xfer_debug", http_xfer_debug)) continue; + if (xp.parse_bool("mem_usage_debug", mem_usage_debug)) continue; + if (xp.parse_bool("network_status_debug", network_status_debug)) continue; + if (xp.parse_bool("poll_debug", poll_debug)) continue; + if (xp.parse_bool("proxy_debug", proxy_debug)) continue; + if (xp.parse_bool("rr_simulation", rr_simulation)) continue; + if (xp.parse_bool("sched_op_debug", sched_op_debug)) continue; + if (xp.parse_bool("scrsave_debug", scrsave_debug)) continue; + if (xp.parse_bool("slot_debug", slot_debug)) continue; + if (xp.parse_bool("state_debug", state_debug)) continue; + if (xp.parse_bool("statefile_debug", statefile_debug)) continue; + if (xp.parse_bool("task_debug", task_debug)) continue; + if (xp.parse_bool("time_debug", time_debug)) continue; + if (xp.parse_bool("unparsed_xml", unparsed_xml)) continue; + if (xp.parse_bool("work_fetch_debug", work_fetch_debug)) continue; + if (xp.parse_bool("notice_debug", notice_debug)) continue; + xp.skip_unexpected(true, "LOG_FLAGS::parse"); } return ERR_XML_PARSE; } @@ -236,32 +233,28 @@ void CONFIG::defaults() { } static bool parse_exclude_gpu(XML_PARSER& xp, EXCLUDE_GPU& eg) { - char tag[1024]; - bool is_tag; bool found_url = false; eg.type = ""; eg.appname = ""; eg.device_num = -1; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/exclude_gpu")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("/exclude_gpu")) { return found_url; } - if (xp.parse_string(tag, "url", eg.url)) { + if (xp.parse_string("url", eg.url)) { canonicalize_master_url(eg.url); found_url = true; continue; } - if (xp.parse_int(tag, "device_num", eg.device_num)) continue; - if (xp.parse_string(tag, "type", eg.type)) continue; - if (xp.parse_string(tag, "app", eg.appname)) continue; + if (xp.parse_int("device_num", eg.device_num)) continue; + if (xp.parse_string("type", eg.type)) continue; + if (xp.parse_string("app", eg.appname)) continue; } return false; } int CONFIG::parse_options(XML_PARSER& xp) { - char tag[1024]; - bool is_tag; string s; int n, retval; @@ -277,148 +270,145 @@ int CONFIG::parse_options(XML_PARSER& xp) { ignore_ati_dev.clear(); exclude_gpus.clear(); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { continue; } - if (!strcmp(tag, "/options")) { + if (xp.match_tag("/options")) { return 0; } - if (xp.parse_bool(tag, "abort_jobs_on_exit", abort_jobs_on_exit)) continue; - if (xp.parse_bool(tag, "allow_multiple_clients", allow_multiple_clients)) continue; - if (xp.parse_bool(tag, "allow_remote_gui_rpc", allow_remote_gui_rpc)) continue; - if (xp.parse_string(tag, "alt_platform", s)) { + if (xp.parse_bool("abort_jobs_on_exit", abort_jobs_on_exit)) continue; + if (xp.parse_bool("allow_multiple_clients", allow_multiple_clients)) continue; + if (xp.parse_bool("allow_remote_gui_rpc", allow_remote_gui_rpc)) continue; + if (xp.parse_string("alt_platform", s)) { alt_platforms.push_back(s); continue; } - if (xp.parse_string(tag, "client_download_url", client_download_url)) { + if (xp.parse_string("client_download_url", client_download_url)) { downcase_string(client_download_url); continue; } - if (xp.parse_string(tag, "client_version_check_url", client_version_check_url)) { + if (xp.parse_string("client_version_check_url", client_version_check_url)) { downcase_string(client_version_check_url); continue; } - if (!strcmp(tag, "coproc")) { + if (xp.match_tag("coproc")) { COPROC c; retval = c.parse(xp); if (retval) return retval; retval = config_coprocs.add(c); continue; } - if (xp.parse_str(tag, "data_dir", data_dir, sizeof(data_dir))) { + if (xp.parse_str("data_dir", data_dir, sizeof(data_dir))) { continue; } - if (xp.parse_bool(tag, "disallow_attach", disallow_attach)) continue; - if (xp.parse_bool(tag, "dont_check_file_sizes", dont_check_file_sizes)) continue; - if (xp.parse_bool(tag, "dont_contact_ref_site", dont_contact_ref_site)) continue; - if (!strcmp(tag, "exclude_gpu")) { + if (xp.parse_bool("disallow_attach", disallow_attach)) continue; + if (xp.parse_bool("dont_check_file_sizes", dont_check_file_sizes)) continue; + if (xp.parse_bool("dont_contact_ref_site", dont_contact_ref_site)) continue; + if (xp.match_tag("exclude_gpu")) { EXCLUDE_GPU eg; if (parse_exclude_gpu(xp, eg)) { exclude_gpus.push_back(eg); } continue; } - if (xp.parse_string(tag, "exclusive_app", s)) { + if (xp.parse_string("exclusive_app", s)) { if (!strstr(s.c_str(), "boinc")) { exclusive_apps.push_back(s); } continue; } - if (xp.parse_string(tag, "exclusive_gpu_app", s)) { + if (xp.parse_string("exclusive_gpu_app", s)) { if (!strstr(s.c_str(), "boinc")) { exclusive_gpu_apps.push_back(s); } continue; } - if (xp.parse_bool(tag, "exit_after_finish", exit_after_finish)) continue; - if (xp.parse_bool(tag, "exit_when_idle", exit_when_idle)) { + if (xp.parse_bool("exit_after_finish", exit_after_finish)) continue; + if (xp.parse_bool("exit_when_idle", exit_when_idle)) { if (exit_when_idle) { report_results_immediately = true; } continue; } - if (xp.parse_bool(tag, "fetch_minimal_work", fetch_minimal_work)) continue; - if (xp.parse_string(tag, "force_auth", force_auth)) { + if (xp.parse_bool("fetch_minimal_work", fetch_minimal_work)) continue; + if (xp.parse_string("force_auth", force_auth)) { downcase_string(force_auth); continue; } - if (xp.parse_bool(tag, "http_1_0", http_1_0)) continue; - if (xp.parse_int(tag, "http_transfer_timeout", http_transfer_timeout)) continue; - if (xp.parse_int(tag, "http_transfer_timeout_bps", http_transfer_timeout_bps)) continue; - if (xp.parse_int(tag, "ignore_cuda_dev", n) || xp.parse_int(tag, "ignore_nvidia_dev", n)) { + if (xp.parse_bool("http_1_0", http_1_0)) continue; + if (xp.parse_int("http_transfer_timeout", http_transfer_timeout)) continue; + if (xp.parse_int("http_transfer_timeout_bps", http_transfer_timeout_bps)) continue; + if (xp.parse_int("ignore_cuda_dev", n) || xp.parse_int("ignore_nvidia_dev", n)) { ignore_nvidia_dev.push_back(n); continue; } - if (xp.parse_int(tag, "ignore_ati_dev", n)) { + if (xp.parse_int("ignore_ati_dev", n)) { ignore_ati_dev.push_back(n); continue; } - if (xp.parse_int(tag, "max_file_xfers", max_file_xfers)) continue; - if (xp.parse_int(tag, "max_file_xfers_per_project", max_file_xfers_per_project)) continue; - if (xp.parse_int(tag, "max_stderr_file_size", max_stderr_file_size)) continue; - if (xp.parse_int(tag, "max_stdout_file_size", max_stdout_file_size)) continue; - if (xp.parse_int(tag, "max_tasks_reported", max_tasks_reported)) continue; - if (xp.parse_int(tag, "ncpus", ncpus)) continue; - if (xp.parse_string(tag, "network_test_url", network_test_url)) { + if (xp.parse_int("max_file_xfers", max_file_xfers)) continue; + if (xp.parse_int("max_file_xfers_per_project", max_file_xfers_per_project)) continue; + if (xp.parse_int("max_stderr_file_size", max_stderr_file_size)) continue; + if (xp.parse_int("max_stdout_file_size", max_stdout_file_size)) continue; + if (xp.parse_int("max_tasks_reported", max_tasks_reported)) continue; + if (xp.parse_int("ncpus", ncpus)) continue; + if (xp.parse_string("network_test_url", network_test_url)) { downcase_string(network_test_url); continue; } - if (xp.parse_bool(tag, "no_alt_platform", no_alt_platform)) continue; - if (xp.parse_bool(tag, "no_gpus", no_gpus)) continue; - if (xp.parse_bool(tag, "no_info_fetch", no_info_fetch)) continue; - if (xp.parse_bool(tag, "no_priority_change", no_priority_change)) continue; - if (xp.parse_bool(tag, "os_random_only", os_random_only)) continue; + if (xp.parse_bool("no_alt_platform", no_alt_platform)) continue; + if (xp.parse_bool("no_gpus", no_gpus)) continue; + if (xp.parse_bool("no_info_fetch", no_info_fetch)) continue; + if (xp.parse_bool("no_priority_change", no_priority_change)) continue; + if (xp.parse_bool("os_random_only", os_random_only)) continue; #ifndef SIM - if (!strcmp(tag, "proxy_info")) { + if (xp.match_tag("proxy_info")) { retval = proxy_info.parse_config(xp); if (retval) return retval; continue; } #endif - if (xp.parse_double(tag, "rec_half_life_days", rec_half_life)) { + if (xp.parse_double("rec_half_life_days", rec_half_life)) { if (rec_half_life <= 0) rec_half_life = 10; rec_half_life *= 86400; continue; } - if (xp.parse_bool(tag, "report_results_immediately", report_results_immediately)) continue; - if (xp.parse_bool(tag, "run_apps_manually", run_apps_manually)) continue; - if (xp.parse_int(tag, "save_stats_days", save_stats_days)) continue; - if (xp.parse_bool(tag, "simple_gui_only", simple_gui_only)) continue; - if (xp.parse_bool(tag, "skip_cpu_benchmarks", skip_cpu_benchmarks)) continue; - if (xp.parse_double(tag, "start_delay", start_delay)) continue; - if (xp.parse_bool(tag, "stderr_head", stderr_head)) continue; - if (xp.parse_bool(tag, "suppress_net_info", suppress_net_info)) continue; - if (xp.parse_bool(tag, "unsigned_apps_ok", unsigned_apps_ok)) continue; - if (xp.parse_bool(tag, "use_all_gpus", use_all_gpus)) continue; - if (xp.parse_bool(tag, "use_certs", use_certs)) continue; - if (xp.parse_bool(tag, "use_certs_only", use_certs_only)) continue; - if (xp.parse_bool(tag, "zero_debts", zero_debts)) continue; + if (xp.parse_bool("report_results_immediately", report_results_immediately)) continue; + if (xp.parse_bool("run_apps_manually", run_apps_manually)) continue; + if (xp.parse_int("save_stats_days", save_stats_days)) continue; + if (xp.parse_bool("simple_gui_only", simple_gui_only)) continue; + if (xp.parse_bool("skip_cpu_benchmarks", skip_cpu_benchmarks)) continue; + if (xp.parse_double("start_delay", start_delay)) continue; + if (xp.parse_bool("stderr_head", stderr_head)) continue; + if (xp.parse_bool("suppress_net_info", suppress_net_info)) continue; + if (xp.parse_bool("unsigned_apps_ok", unsigned_apps_ok)) continue; + if (xp.parse_bool("use_all_gpus", use_all_gpus)) continue; + if (xp.parse_bool("use_certs", use_certs)) continue; + if (xp.parse_bool("use_certs_only", use_certs_only)) continue; + if (xp.parse_bool("zero_debts", zero_debts)) continue; - xp.skip_unexpected(tag, true, "CONFIG::parse_options"); + xp.skip_unexpected(true, "CONFIG::parse_options"); } return ERR_XML_PARSE; } int CONFIG::parse(XML_PARSER& xp, LOG_FLAGS& log_flags) { - char tag[256]; - bool is_tag; - - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { continue; } - if (!strcmp(tag, "/cc_config")) return 0; - if (!strcmp(tag, "log_flags")) { + if (xp.match_tag("/cc_config")) return 0; + if (xp.match_tag("log_flags")) { log_flags.parse(xp); continue; } - if (!strcmp(tag, "options")) { + if (xp.match_tag("options")) { parse_options(xp); continue; } - if (!strcmp(tag, "options/")) continue; - if (!strcmp(tag, "log_flags/")) continue; + if (xp.match_tag("options/")) continue; + if (xp.match_tag("log_flags/")) continue; } return ERR_XML_PARSE; } diff --git a/lib/cert_sig.cpp b/lib/cert_sig.cpp index 04eb8e8f8f..aea20f94ce 100644 --- a/lib/cert_sig.cpp +++ b/lib/cert_sig.cpp @@ -68,30 +68,28 @@ int CERT_SIGS::count() { int CERT_SIGS::parse(XML_PARSER &xp) { CERT_SIG sig; - bool is_tag = false; bool in_entry = false; bool in_sig = false; bool parsed_one = false; - char tag[4096]; char buf[256]; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!strcmp(tag, "/signatures")) { + while (!xp.get_tag()) { + if (xp.match_tag("/signatures")) { //printf("CERT_SIGS::parse() ends.\n"); //fflush(stdout); return !in_entry && !in_sig && parsed_one; } if (in_sig) { in_sig = false; - snprintf(sig.signature, sizeof(sig.signature), "%s", tag); + snprintf(sig.signature, sizeof(sig.signature), "%s", xp.parsed_tag); continue; } - if (!is_tag) { - printf("(CERT_SIGS): unexpected text: %s\n", tag); + if (!xp.is_tag) { + printf("(CERT_SIGS): unexpected text: %s\n", xp.parsed_tag); continue; } if (in_entry) { - if (!strcmp(tag, "/entry")) { + if (xp.match_tag("/entry")) { in_entry = false; in_sig = false; if (strlen(sig.subject) == 0) { @@ -107,19 +105,19 @@ int CERT_SIGS::parse(XML_PARSER &xp) { sig.clear(); continue; } - if (!strcmp(tag, "signature")) { + if (xp.match_tag("signature")) { in_sig = true; continue; } - if (!strcmp(tag, "/signature")) { + if (xp.match_tag("/signature")) { in_sig = false; continue; } - if (xp.parse_str(tag, "subject", sig.subject, sizeof(sig.subject))) + if (xp.parse_str("subject", sig.subject, sizeof(sig.subject))) continue; - else if (xp.parse_str(tag, "hash", sig.hash, sizeof(sig.hash))) + else if (xp.parse_str("hash", sig.hash, sizeof(sig.hash))) continue; - else if (xp.parse_str(tag, "type", buf, sizeof(buf))) { + else if (xp.parse_str("type", buf, sizeof(buf))) { if ((!strcmp(buf,"md5")) || (!strcmp(buf,"MD5"))) { sig.type = MD5_HASH; } else if ((!strcmp(buf,"sha1")) || (!strcmp(buf,"SHA1"))) { @@ -128,7 +126,7 @@ int CERT_SIGS::parse(XML_PARSER &xp) { continue; } } else { - if (strstr(tag, "entry")) { + if (strstr(xp.parsed_tag, "entry")) { in_entry = true; continue; } @@ -183,7 +181,7 @@ int CERT_SIGS::parse_buffer_embed(char* buf) { mf.init_buf_read(buf); XML_PARSER xp(&mf); while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!strcmp(tag, "signatures")) { + if (xp.match_tag("signatures")) { s_found = true; break; } diff --git a/lib/coproc.cpp b/lib/coproc.cpp index 6aee5b2616..f99c0f9a19 100644 --- a/lib/coproc.cpp +++ b/lib/coproc.cpp @@ -86,23 +86,22 @@ void COPROC::write_request(MIOFILE& f) { int COPROC::parse(XML_PARSER& xp) { //TODO: Parse opencl_prop - char tag[1024], buf[256]; - bool is_tag; + char buf[256]; strcpy(type, ""); clear(); for (int i=0; i\n"); if (retval) return retval; - while (!xp.get(buf, sizeof(buf), is_tag)) { - if (!is_tag) continue; - if (xp.parse_str(buf, "nonce", nonce, sizeof(nonce))) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.parse_str("nonce", nonce, sizeof(nonce))) { found = true; break; } @@ -258,9 +258,9 @@ int RPC_CLIENT::authorize(const char* passwd) { sprintf(buf, "\n%s\n\n", nonce_hash); retval = rpc.do_rpc(buf); if (retval) return retval; - while (!xp.get(buf, sizeof(buf), is_tag)) { - if (!is_tag) continue; - if (xp.parse_bool(buf, "authorized", authorized)) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.parse_bool("authorized", authorized)) { if (authorized) return 0; break; } diff --git a/lib/gui_rpc_client_ops.cpp b/lib/gui_rpc_client_ops.cpp index 072ff99b0d..2c76b60fde 100644 --- a/lib/gui_rpc_client_ops.cpp +++ b/lib/gui_rpc_client_ops.cpp @@ -102,32 +102,30 @@ PROJECT_LIST_ENTRY::~PROJECT_LIST_ENTRY() { } int PROJECT_LIST_ENTRY::parse(XML_PARSER& xp) { - char tag[256]; - bool is_tag; string platform; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!strcmp(tag, "/project")) return 0; - if (xp.parse_string(tag, "name", name)) continue; - if (xp.parse_string(tag, "url", url)) { + while (!xp.get_tag()) { + if (xp.match_tag("/project")) return 0; + if (xp.parse_string("name", name)) continue; + if (xp.parse_string("url", url)) { continue; } - if (xp.parse_string(tag, "general_area", general_area)) continue; - if (xp.parse_string(tag, "specific_area", specific_area)) continue; - if (xp.parse_string(tag, "description", description)) { + if (xp.parse_string("general_area", general_area)) continue; + if (xp.parse_string("specific_area", specific_area)) continue; + if (xp.parse_string("description", description)) { continue; } - if (xp.parse_string(tag, "home", home)) continue; - if (xp.parse_string(tag, "image", image)) continue; - if (!strcmp(tag, "platforms")) { - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!strcmp(tag, "/platforms")) break; - if (xp.parse_string(tag, "name", platform)) { + if (xp.parse_string("home", home)) continue; + if (xp.parse_string("image", image)) continue; + if (xp.match_tag("platforms")) { + while (!xp.get_tag()) { + if (xp.match_tag("/platforms")) break; + if (xp.parse_string("name", platform)) { platforms.push_back(platform); } } } - xp.skip_unexpected(tag, false, ""); + xp.skip_unexpected(false, ""); } return ERR_XML_PARSE; } @@ -152,14 +150,12 @@ AM_LIST_ENTRY::~AM_LIST_ENTRY() { } int AM_LIST_ENTRY::parse(XML_PARSER& xp) { - char tag[256]; - bool is_tag; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!strcmp(tag, "/account_manager")) return 0; - if (xp.parse_string(tag, "name", name)) continue; - if (xp.parse_string(tag, "url", url)) continue; - if (xp.parse_string(tag, "description", description)) continue; - if (xp.parse_string(tag, "image", image)) continue; + while (!xp.get_tag()) { + if (xp.match_tag("/account_manager")) return 0; + if (xp.parse_string("name", name)) continue; + if (xp.parse_string("url", url)) continue; + if (xp.parse_string("description", description)) continue; + if (xp.parse_string("image", image)) continue; } return 0; } @@ -1459,8 +1455,6 @@ int RPC_CLIENT::get_project_status(PROJECTS& p) { int RPC_CLIENT::get_all_projects_list(ALL_PROJECTS_LIST& pl) { int retval = 0; SET_LOCALE sl; - char tag[256]; - bool is_tag; MIOFILE mf; PROJECT_LIST_ENTRY* project; AM_LIST_ENTRY* am; @@ -1470,9 +1464,9 @@ int RPC_CLIENT::get_all_projects_list(ALL_PROJECTS_LIST& pl) { retval = rpc.do_rpc("\n"); if (retval) return retval; - while (!rpc.xp.get(tag, sizeof(tag), is_tag)) { - if (!strcmp(tag, "/projects")) break; - else if (!strcmp(tag, "project")) { + while (!rpc.xp.get_tag()) { + if (rpc.xp.match_tag("/projects")) break; + else if (rpc.xp.match_tag("project")) { project = new PROJECT_LIST_ENTRY(); retval = project->parse(rpc.xp); if (!retval) { @@ -1481,7 +1475,7 @@ int RPC_CLIENT::get_all_projects_list(ALL_PROJECTS_LIST& pl) { delete project; } continue; - } else if (!strcmp(tag, "account_manager")) { + } else if (rpc.xp.match_tag("account_manager")) { am = new AM_LIST_ENTRY(); retval = am->parse(rpc.xp); if (!retval) { @@ -2433,13 +2427,11 @@ int RPC_CLIENT::set_cc_config(CONFIG& config, LOG_FLAGS& log_flags) { } static int parse_notices(XML_PARSER& xp, NOTICES& notices) { - char tag[256]; - bool is_tag; int retval; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "notice")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("notice")) { NOTICE* np = new NOTICE(); retval = np->parse(xp); if (!retval) { diff --git a/lib/miofile.h b/lib/miofile.h index f86e1d3c09..43eda386fc 100644 --- a/lib/miofile.h +++ b/lib/miofile.h @@ -46,11 +46,12 @@ class MIOFILE { MFILE* mf; - FILE* f; char* wbuf; int len; const char* buf; public: + FILE* f; + MIOFILE(); ~MIOFILE(); void init_mfile(MFILE*); diff --git a/lib/notice.cpp b/lib/notice.cpp index 01120ae0c3..0b90369fb9 100644 --- a/lib/notice.cpp +++ b/lib/notice.cpp @@ -39,29 +39,26 @@ NOTICE::~NOTICE() { // parse_rss() parses an RSS feed item. // int NOTICE::parse(XML_PARSER& xp) { - char tag[1024]; - bool is_tag; - clear(); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/notice")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("/notice")) { return 0; } - if (xp.parse_int(tag, "seqno", seqno)) continue; - if (xp.parse_str(tag, "title", title, sizeof(title))) continue; - if (xp.parse_string(tag, "description", description)) { + if (xp.parse_int("seqno", seqno)) continue; + if (xp.parse_str("title", title, sizeof(title))) continue; + if (xp.parse_string("description", description)) { xml_unescape(description); // 2nd pass continue; } - if (xp.parse_double(tag, "create_time", create_time)) continue; - if (xp.parse_double(tag, "arrival_time", arrival_time)) continue; - if (xp.parse_bool(tag, "is_private", is_private)) continue; - if (xp.parse_str(tag, "category", category, sizeof(category))) continue; - if (xp.parse_str(tag, "link", link, sizeof(link))) continue; - if (xp.parse_str(tag, "project_name", project_name, sizeof(project_name))) continue; - if (xp.parse_str(tag, "guid", guid, sizeof(guid))) continue; - if (xp.parse_str(tag, "feed_url", feed_url, sizeof(feed_url))) continue; + if (xp.parse_double("create_time", create_time)) continue; + if (xp.parse_double("arrival_time", arrival_time)) continue; + if (xp.parse_bool("is_private", is_private)) continue; + if (xp.parse_str("category", category, sizeof(category))) continue; + if (xp.parse_str("link", link, sizeof(link))) continue; + if (xp.parse_str("project_name", project_name, sizeof(project_name))) continue; + if (xp.parse_str("guid", guid, sizeof(guid))) continue; + if (xp.parse_str("feed_url", feed_url, sizeof(feed_url))) continue; } return ERR_XML_PARSE; } diff --git a/lib/parse.cpp b/lib/parse.cpp index 4ea796f445..6017ffd5a9 100644 --- a/lib/parse.cpp +++ b/lib/parse.cpp @@ -540,7 +540,7 @@ int XML_PARSER::scan_cdata(char* buf, int len) { // we just read a <; read until we find a >. // Given : -// - copy tag (or tag/) to tag_buf +// - copy tag (or tag/) to buf // - copy "attr=val attr=val" to attr_buf // // Return either @@ -550,10 +550,10 @@ int XML_PARSER::scan_cdata(char* buf, int len) { // XML_PARSE_CDATA // int XML_PARSER::scan_tag( - char* tag_buf, int _tag_len, char* attr_buf, int attr_len + char* buf, int _tag_len, char* attr_buf, int attr_len ) { int c; - char* buf_start = tag_buf; + char* buf_start = buf; bool found_space = false; int tag_len = _tag_len; @@ -561,7 +561,7 @@ int XML_PARSER::scan_tag( c = f->_getc(); if (c == EOF) return XML_PARSE_EOF; if (c == '>') { - *tag_buf = 0; + *buf = 0; if (attr_buf) *attr_buf = 0; return XML_PARSE_TAG; } @@ -574,7 +574,7 @@ int XML_PARSER::scan_tag( found_space = true; } else if (c == '/') { if (--tag_len > 0) { - *tag_buf++ = c; + *buf++ = c; } } else { if (found_space) { @@ -585,7 +585,7 @@ int XML_PARSER::scan_tag( } } else { if (--tag_len > 0) { - *tag_buf++ = c; + *buf++ = c; } } } @@ -647,16 +647,16 @@ int XML_PARSER::get_aux(char* buf, int len, char* attr_buf, int attr_len) { } } -bool XML_PARSER::get(char* buf, int len, bool& is_tag, char* attr_buf, int attr_len) { +bool XML_PARSER::get(char* buf, int len, bool& _is_tag, char* attr_buf, int attr_len) { switch (get_aux(buf, len, attr_buf, attr_len)) { case XML_PARSE_EOF: return true; case XML_PARSE_TAG: - is_tag = true; + _is_tag = true; break; case XML_PARSE_DATA: case XML_PARSE_CDATA: default: - is_tag = false; + _is_tag = false; break; } return false; @@ -667,10 +667,8 @@ bool XML_PARSER::get(char* buf, int len, bool& is_tag, char* attr_buf, int attr_ // and by the matching close tag, return the string in "buf", // and return true. // -bool XML_PARSER::parse_str( - char* parsed_tag, const char* start_tag, char* buf, int len -) { - bool is_tag, eof; +bool XML_PARSER::parse_str(const char* start_tag, char* buf, int len) { + bool eof; char end_tag[256], tag[256], tmp[64000]; // handle the archaic form , which means empty string @@ -720,11 +718,9 @@ bool XML_PARSER::parse_str( return true; } -bool XML_PARSER::parse_string( - char* parsed_tag, const char* start_tag, string& str -) { +bool XML_PARSER::parse_string(const char* start_tag, string& str) { char buf[8192]; - bool flag = parse_str(parsed_tag, start_tag, buf, sizeof(buf)); + bool flag = parse_str(start_tag, buf, sizeof(buf)); if (!flag) return false; str = buf; return true; @@ -732,9 +728,9 @@ bool XML_PARSER::parse_string( // Same, for integers // -bool XML_PARSER::parse_int(char* parsed_tag, const char* start_tag, int& i) { +bool XML_PARSER::parse_int(const char* start_tag, int& i) { char buf[256], *end; - bool is_tag, eof; + bool eof; char end_tag[256], tag[256]; if (strcmp(parsed_tag, start_tag)) return false; @@ -767,9 +763,9 @@ bool XML_PARSER::parse_int(char* parsed_tag, const char* start_tag, int& i) { // Same, for doubles // -bool XML_PARSER::parse_double(char* parsed_tag, const char* start_tag, double& x) { +bool XML_PARSER::parse_double(const char* start_tag, double& x) { char buf[256], *end; - bool is_tag, eof; + bool eof; char end_tag[256], tag[256]; if (strcmp(parsed_tag, start_tag)) return false; @@ -800,9 +796,9 @@ bool XML_PARSER::parse_double(char* parsed_tag, const char* start_tag, double& x // Same, for bools // -bool XML_PARSER::parse_bool(char* parsed_tag, const char* start_tag, bool& b) { +bool XML_PARSER::parse_bool(const char* start_tag, bool& b) { char buf[256], *end; - bool is_tag, eof; + bool eof; char end_tag[256], tag[256]; // handle the archaic form , which means true @@ -838,7 +834,7 @@ bool XML_PARSER::parse_bool(char* parsed_tag, const char* start_tag, bool& b) { // bool XML_PARSER::parse_start(const char* start_tag) { char tag[256]; - bool eof, is_tag; + bool eof; eof = get(tag, sizeof(tag), is_tag); if (eof || !is_tag ) { @@ -894,7 +890,6 @@ void XML_PARSER::skip_unexpected( const char* start_tag, bool verbose, const char* where ) { char tag[256], end_tag[256]; - bool is_tag; if (verbose) { fprintf(stderr, "Unrecognized XML in %s: %s\n", where, start_tag); @@ -933,8 +928,7 @@ int XML_PARSER::element(const char* start_tag, char* buf, int buflen) { #if 0 void parse(FILE* f) { - char tag[256]; - bool is_tag, flag; + bool flag; MIOFILE mf; XML_PARSER xp(&mf); char name[256]; @@ -946,25 +940,25 @@ void parse(FILE* f) { printf("missing start tag\n"); return; } - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { printf("unexpected text: %s\n", tag); continue; } - if (!strcmp(tag, "/blah")) { + if (xp.match_tag("/blah")) { printf("success\n"); return; - } else if (xp.parse_str(tag, "str", name, sizeof(name))) { + } else if (xp.parse_str("str", name, sizeof(name))) { printf("got str: %s\n", name); - } else if (xp.parse_int(tag, "int", val)) { + } else if (xp.parse_int("int", val)) { printf("got int: %d\n", val); - } else if (xp.parse_double(tag, "double", x)) { + } else if (xp.parse_double("double", x)) { printf("got double: %f\n", x); - } else if (xp.parse_bool(tag, "bool", flag)) { + } else if (xp.parse_bool("bool", flag)) { printf("got bool: %d\n", flag); } else { - printf("unparsed tag: %s\n", tag); - xp.skip_unexpected(tag, true, "xml test"); + printf("unparsed tag: %s\n", xp.parsed_tag); + xp.skip_unexpected(true, "xml test"); } } printf("unexpected EOF\n"); diff --git a/lib/parse.h b/lib/parse.h index 9e20b39239..a5d3623672 100644 --- a/lib/parse.h +++ b/lib/parse.h @@ -32,19 +32,30 @@ class XML_PARSER { int scan_cdata(char*, int); bool copy_until_tag(char*, int); public: + char parsed_tag[4096]; + bool is_tag; MIOFILE* f; XML_PARSER(MIOFILE*); bool get(char*, int, bool&, char* ab=0, int al=0); + inline bool get_tag(char* ab=0, int al=0) { + return get(parsed_tag, sizeof(parsed_tag), is_tag, ab, al); + } + inline bool match_tag(const char* tag) { + return !strcmp(parsed_tag, tag); + } int get_aux(char* buf, int len, char* attr_buf, int attr_len); bool parse_start(const char*); - bool parse_str(char*, const char*, char*, int); - bool parse_string(char*, const char*, std::string&); - bool parse_int(char*, const char*, int&); - bool parse_double(char*, const char*, double&); - bool parse_bool(char*, const char*, bool&); + bool parse_str(const char*, char*, int); + bool parse_string(const char*, std::string&); + bool parse_int(const char*, int&); + bool parse_double(const char*, double&); + bool parse_bool(const char*, bool&); int element_contents(const char*, char*, int); int element(const char*, char*, int); void skip_unexpected(const char*, bool verbose, const char*); + void skip_unexpected(bool verbose, const char* msg) { + skip_unexpected(parsed_tag, verbose, msg); + } }; extern bool boinc_is_finite(double); diff --git a/lib/prefs.cpp b/lib/prefs.cpp index 4c6dde669e..b0291120a9 100644 --- a/lib/prefs.cpp +++ b/lib/prefs.cpp @@ -276,9 +276,6 @@ int GLOBAL_PREFS::parse( } int GLOBAL_PREFS::parse_day(XML_PARSER& xp) { - char tag[256]; - bool is_tag; - int day_of_week = -1; bool has_cpu = false; bool has_net = false; @@ -287,9 +284,9 @@ int GLOBAL_PREFS::parse_day(XML_PARSER& xp) { double net_start_hour = 0; double net_end_hour = 0; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/day_prefs")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("/day_prefs")) { if (day_of_week < 0 || day_of_week > 6) return ERR_XML_PARSE; if (has_cpu) { cpu_times.week.set(day_of_week, start_hour, end_hour); @@ -299,24 +296,24 @@ int GLOBAL_PREFS::parse_day(XML_PARSER& xp) { } return 0; } - if (xp.parse_int(tag, "day_of_week", day_of_week)) continue; - if (xp.parse_double(tag, "start_hour", start_hour)) { + if (xp.parse_int("day_of_week", day_of_week)) continue; + if (xp.parse_double("start_hour", start_hour)) { has_cpu = true; continue; } - if (xp.parse_double(tag, "end_hour", end_hour)) { + if (xp.parse_double("end_hour", end_hour)) { has_cpu = true; continue; } - if (xp.parse_double(tag, "net_start_hour", net_start_hour)) { + if (xp.parse_double("net_start_hour", net_start_hour)) { has_net = true; continue; } - if (xp.parse_double(tag, "net_end_hour", net_end_hour)) { + if (xp.parse_double("net_end_hour", net_end_hour)) { has_net = true; continue; } - xp.skip_unexpected(tag, true, "GLOBAL_PREFS::parse_day"); + xp.skip_unexpected(true, "GLOBAL_PREFS::parse_day"); } return ERR_XML_PARSE; } @@ -336,22 +333,22 @@ int GLOBAL_PREFS::parse_day(XML_PARSER& xp) { int GLOBAL_PREFS::parse_override( XML_PARSER& xp, const char* host_venue, bool& found_venue, GLOBAL_PREFS_MASK& mask ) { - char tag[256], buf2[256], attrs[256]; - bool in_venue = false, in_correct_venue=false, is_tag; + char buf2[256], attrs[256]; + bool in_venue = false, in_correct_venue=false; double dtemp; int itemp; found_venue = false; mask.clear(); - while (!xp.get(tag, sizeof(tag), is_tag, attrs, sizeof(attrs))) { - if (!is_tag) continue; - if (!strcmp(tag, "global_preferences")) continue; - if (!strcmp(tag, "/global_preferences")) { + while (!xp.get_tag(attrs, sizeof(attrs))) { + if (!xp.is_tag) continue; + if (xp.match_tag("global_preferences")) continue; + if (xp.match_tag("/global_preferences")) { return 0; } if (in_venue) { - if (!strcmp(tag, "/venue")) { + if (xp.match_tag("/venue")) { if (in_correct_venue) { return 0; } else { @@ -362,7 +359,7 @@ int GLOBAL_PREFS::parse_override( if (!in_correct_venue) continue; } } else { - if (strstr(tag, "venue")) { + if (strstr(xp.parsed_tag, "venue")) { in_venue = true; parse_attr(attrs, "name", buf2, sizeof(buf2)); if (!strcmp(buf2, host_venue)) { @@ -377,78 +374,78 @@ int GLOBAL_PREFS::parse_override( continue; } } - if (xp.parse_str(tag, "source_project", source_project, sizeof(source_project))) continue; - if (xp.parse_str(tag, "source_scheduler", source_scheduler, sizeof(source_scheduler))) { + if (xp.parse_str("source_project", source_project, sizeof(source_project))) continue; + if (xp.parse_str("source_scheduler", source_scheduler, sizeof(source_scheduler))) { continue; } - if (xp.parse_double(tag, "mod_time", mod_time)) { + if (xp.parse_double("mod_time", mod_time)) { double now = dtime(); if (mod_time > now) { mod_time = now; } continue; } - if (xp.parse_bool(tag, "run_on_batteries", run_on_batteries)) { + if (xp.parse_bool("run_on_batteries", run_on_batteries)) { mask.run_on_batteries = true; continue; } - if (xp.parse_bool(tag, "run_if_user_active", run_if_user_active)) { + if (xp.parse_bool("run_if_user_active", run_if_user_active)) { mask.run_if_user_active = true; continue; } - if (xp.parse_bool(tag, "run_gpu_if_user_active", run_gpu_if_user_active)) { + if (xp.parse_bool("run_gpu_if_user_active", run_gpu_if_user_active)) { mask.run_gpu_if_user_active = true; continue; } - if (xp.parse_double(tag, "idle_time_to_run", idle_time_to_run)) { + if (xp.parse_double("idle_time_to_run", idle_time_to_run)) { mask.idle_time_to_run = true; continue; } - if (xp.parse_double(tag, "suspend_if_no_recent_input", suspend_if_no_recent_input)) { + if (xp.parse_double("suspend_if_no_recent_input", suspend_if_no_recent_input)) { mask.suspend_if_no_recent_input = true; continue; } - if (xp.parse_double(tag, "suspend_cpu_usage", suspend_cpu_usage)) { + if (xp.parse_double("suspend_cpu_usage", suspend_cpu_usage)) { mask.suspend_cpu_usage = true; continue; } - if (xp.parse_double(tag, "start_hour", cpu_times.start_hour)) { + if (xp.parse_double("start_hour", cpu_times.start_hour)) { mask.start_hour = true; continue; } - if (xp.parse_double(tag, "end_hour", cpu_times.end_hour)) { + if (xp.parse_double("end_hour", cpu_times.end_hour)) { mask.end_hour = true; continue; } - if (xp.parse_double(tag, "net_start_hour", net_times.start_hour)) { + if (xp.parse_double("net_start_hour", net_times.start_hour)) { mask.net_start_hour = true; continue; } - if (xp.parse_double(tag, "net_end_hour", net_times.end_hour)) { + if (xp.parse_double("net_end_hour", net_times.end_hour)) { mask.net_end_hour = true; continue; } - if (!strcmp(tag, "day_prefs")) { + if (xp.match_tag("day_prefs")) { parse_day(xp); continue; } - if (xp.parse_bool(tag, "leave_apps_in_memory", leave_apps_in_memory)) { + if (xp.parse_bool("leave_apps_in_memory", leave_apps_in_memory)) { mask.leave_apps_in_memory = true; continue; } - if (xp.parse_bool(tag, "confirm_before_connecting", confirm_before_connecting)) { + if (xp.parse_bool("confirm_before_connecting", confirm_before_connecting)) { mask.confirm_before_connecting = true; continue; } - if (xp.parse_bool(tag, "hangup_if_dialed", hangup_if_dialed)) { + if (xp.parse_bool("hangup_if_dialed", hangup_if_dialed)) { mask.hangup_if_dialed = true; continue; } - if (xp.parse_bool(tag, "dont_verify_images", dont_verify_images)) { + if (xp.parse_bool("dont_verify_images", dont_verify_images)) { mask.dont_verify_images = true; continue; } - if (xp.parse_double(tag, "work_buf_min_days", work_buf_min_days)) { + if (xp.parse_double("work_buf_min_days", work_buf_min_days)) { // the following is for compatibility with old schedulers, // whose work req is just #secs, rather than #sec and #devices // If this were zero we'd never get work from them @@ -457,97 +454,97 @@ int GLOBAL_PREFS::parse_override( mask.work_buf_min_days = true; continue; } - if (xp.parse_double(tag, "work_buf_additional_days", work_buf_additional_days)) { + if (xp.parse_double("work_buf_additional_days", work_buf_additional_days)) { if (work_buf_additional_days < 0) work_buf_additional_days = 0; mask.work_buf_additional_days = true; continue; } - if (xp.parse_double(tag, "max_ncpus_pct", max_ncpus_pct)) { + if (xp.parse_double("max_ncpus_pct", max_ncpus_pct)) { if (max_ncpus_pct < 0) max_ncpus_pct = 0; if (max_ncpus_pct > 100) max_ncpus_pct = 100; mask.max_ncpus_pct = true; continue; } - if (xp.parse_int(tag, "max_cpus", max_ncpus)) { + if (xp.parse_int("max_cpus", max_ncpus)) { if (max_ncpus < 0) max_ncpus = 0; mask.max_ncpus = true; continue; } - if (xp.parse_double(tag, "disk_interval", disk_interval)) { + if (xp.parse_double("disk_interval", disk_interval)) { if (disk_interval<0) disk_interval = 0; mask.disk_interval = true; continue; } - if (xp.parse_double(tag, "cpu_scheduling_period_minutes", cpu_scheduling_period_minutes)) { + if (xp.parse_double("cpu_scheduling_period_minutes", cpu_scheduling_period_minutes)) { if (cpu_scheduling_period_minutes < 0.0001) cpu_scheduling_period_minutes = 60; mask.cpu_scheduling_period_minutes = true; continue; } - if (xp.parse_double(tag, "disk_max_used_gb", disk_max_used_gb)) { + if (xp.parse_double("disk_max_used_gb", disk_max_used_gb)) { mask.disk_max_used_gb = true; continue; } - if (xp.parse_double(tag, "disk_max_used_pct", disk_max_used_pct)) { + if (xp.parse_double("disk_max_used_pct", disk_max_used_pct)) { mask.disk_max_used_pct = true; continue; } - if (xp.parse_double(tag, "disk_min_free_gb", disk_min_free_gb)) { + if (xp.parse_double("disk_min_free_gb", disk_min_free_gb)) { mask.disk_min_free_gb = true; continue; } - if (xp.parse_double(tag, "vm_max_used_pct", dtemp)) { + if (xp.parse_double("vm_max_used_pct", dtemp)) { vm_max_used_frac = dtemp/100; mask.vm_max_used_frac = true; continue; } - if (xp.parse_double(tag, "ram_max_used_busy_pct", dtemp)) { + if (xp.parse_double("ram_max_used_busy_pct", dtemp)) { if (!dtemp) dtemp = 100; ram_max_used_busy_frac = dtemp/100; mask.ram_max_used_busy_frac = true; continue; } - if (xp.parse_double(tag, "ram_max_used_idle_pct", dtemp)) { + if (xp.parse_double("ram_max_used_idle_pct", dtemp)) { if (!dtemp) dtemp = 100; ram_max_used_idle_frac = dtemp/100; mask.ram_max_used_idle_frac = true; continue; } - if (xp.parse_double(tag, "max_bytes_sec_up", max_bytes_sec_up)) { + if (xp.parse_double("max_bytes_sec_up", max_bytes_sec_up)) { if (max_bytes_sec_up < 0) max_bytes_sec_up = 0; mask.max_bytes_sec_up = true; continue; } - if (xp.parse_double(tag, "max_bytes_sec_down", max_bytes_sec_down)) { + if (xp.parse_double("max_bytes_sec_down", max_bytes_sec_down)) { if (max_bytes_sec_down < 0) max_bytes_sec_down = 0; mask.max_bytes_sec_down = true; continue; } - if (xp.parse_double(tag, "cpu_usage_limit", dtemp)) { + if (xp.parse_double("cpu_usage_limit", dtemp)) { if (dtemp > 0 && dtemp <= 100) { cpu_usage_limit = dtemp; mask.cpu_usage_limit = true; } continue; } - if (xp.parse_double(tag, "daily_xfer_limit_mb", dtemp)) { + if (xp.parse_double("daily_xfer_limit_mb", dtemp)) { if (dtemp >= 0) { daily_xfer_limit_mb = dtemp; mask.daily_xfer_limit_mb = true; } continue; } - if (xp.parse_int(tag, "daily_xfer_period_days", itemp)) { + if (xp.parse_int("daily_xfer_period_days", itemp)) { if (itemp >= 0) { daily_xfer_period_days = itemp; mask.daily_xfer_period_days = true; } continue; } - if (xp.parse_bool(tag, "host_specific", host_specific)) { + if (xp.parse_bool("host_specific", host_specific)) { continue; } // false means don't print anything - xp.skip_unexpected(tag, false, "GLOBAL_PREFS::parse_override"); + xp.skip_unexpected(false, "GLOBAL_PREFS::parse_override"); } return ERR_XML_PARSE; } diff --git a/sched/delete_file.cpp b/sched/delete_file.cpp index bc7a38ef45..6d5c1755e2 100644 --- a/sched/delete_file.cpp +++ b/sched/delete_file.cpp @@ -47,8 +47,7 @@ void usage(char* name) { " --file_name F file name\n" " --host_id H host DB ID\n" " [-h | --help] Show this help text.\n" - " [-v | --version] Show version information.\n", - name + " [-v | --version] Show version information.\n" ); } diff --git a/sched/edf_sim.h b/sched/edf_sim.h index 94a9b4e8bf..1860b2d44b 100644 --- a/sched/edf_sim.h +++ b/sched/edf_sim.h @@ -26,7 +26,7 @@ struct IP_RESULT { double computation_deadline; double report_deadline; double cpu_time_remaining; - int parse(FILE*); + int parse(XML_PARSER&); /// Whether or not the result would have missed its deadline, /// independent of any newly scheduled result /// Used to determine if late results will complete even later diff --git a/sched/handle_request.cpp b/sched/handle_request.cpp index 16d436dab5..56f6557e64 100644 --- a/sched/handle_request.cpp +++ b/sched/handle_request.cpp @@ -1349,7 +1349,10 @@ void handle_request(FILE* fin, FILE* fout, char* code_sign_key) { log_messages.set_indent_level(1); - const char* p = sreq.parse(fin); + MIOFILE mf; + XML_PARSER xp(&mf); + mf.init_file(fin); + const char* p = sreq.parse(xp); double start_time = dtime(); if (!p){ process_request(code_sign_key); diff --git a/sched/sched_config.cpp b/sched/sched_config.cpp index 9ff3efc720..afc04b5338 100644 --- a/sched/sched_config.cpp +++ b/sched/sched_config.cpp @@ -45,21 +45,22 @@ const int MAX_NCPUS = 64; // need to change as multicore processors expand int SCHED_CONFIG::parse_aux(FILE* f) { - char tag[1024]; - bool is_tag; MIOFILE mf; XML_PARSER xp(&mf); mf.init_file(f); if (!xp.parse_start("config")) return ERR_XML_PARSE; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { - fprintf(stderr, "SCHED_CONFIG::parse(): unexpected text %s\n", tag); + while (!xp.get_tag()) { + if (!xp.is_tag) { + fprintf(stderr, + "SCHED_CONFIG::parse(): unexpected text %s\n", + xp.parsed_tag + ); continue; } - if (!strcmp(tag, "/config")) { + if (xp.match_tag("/config")) { return 0; } - if (!strcmp(tag, "max_jobs_in_progress")) { + if (xp.match_tag("max_jobs_in_progress")) { max_jobs_in_progress.parse(xp, "/max_jobs_in_progress"); } } @@ -67,8 +68,7 @@ int SCHED_CONFIG::parse_aux(FILE* f) { } int SCHED_CONFIG::parse(FILE* f) { - char tag[1024], buf[256]; - bool is_tag; + char buf[256]; MIOFILE mf; XML_PARSER xp(&mf); int retval, itemp; @@ -93,12 +93,15 @@ int SCHED_CONFIG::parse(FILE* f) { if (!xp.parse_start("boinc")) return ERR_XML_PARSE; if (!xp.parse_start("config")) return ERR_XML_PARSE; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { - fprintf(stderr, "SCHED_CONFIG::parse(): unexpected text %s\n", tag); + while (!xp.get_tag()) { + if (!xp.is_tag) { + fprintf(stderr, + "SCHED_CONFIG::parse(): unexpected text %s\n", + xp.parsed_tag + ); continue; } - if (!strcmp(tag, "/config")) { + if (xp.match_tag("/config")) { char hostname[256]; gethostname(hostname, 256); if (!strcmp(hostname, db_host)) strcpy(db_host, "localhost"); @@ -116,32 +119,32 @@ int SCHED_CONFIG::parse(FILE* f) { } return 0; } - if (xp.parse_str(tag, "master_url", master_url, sizeof(master_url))) continue; - if (xp.parse_str(tag, "long_name", long_name, sizeof(long_name))) continue; - if (xp.parse_str(tag, "db_name", db_name, sizeof(db_name))) continue; - if (xp.parse_str(tag, "db_user", db_user, sizeof(db_user))) continue; - if (xp.parse_str(tag, "db_passwd", db_passwd, sizeof(db_passwd))) continue; - if (xp.parse_str(tag, "db_host", db_host, sizeof(db_host))) continue; - if (xp.parse_str(tag, "replica_db_name", replica_db_name, sizeof(replica_db_name))) continue; - if (xp.parse_str(tag, "replica_db_user", replica_db_user, sizeof(replica_db_user))) continue; - if (xp.parse_str(tag, "replica_db_passwd", replica_db_passwd, sizeof(replica_db_passwd))) continue; - if (xp.parse_str(tag, "replica_db_host", replica_db_host, sizeof(replica_db_host))) continue; - if (xp.parse_str(tag, "project_dir", project_dir, sizeof(project_dir))) continue; - if (xp.parse_int(tag, "shmem_key", shmem_key)) continue; - if (xp.parse_str(tag, "key_dir", key_dir, sizeof(key_dir))) continue; - if (xp.parse_str(tag, "download_url", download_url, sizeof(download_url))) continue; - if (xp.parse_str(tag, "download_dir", download_dir, sizeof(download_dir))) continue; - if (xp.parse_str(tag, "upload_url", upload_url, sizeof(upload_url))) continue; - if (xp.parse_str(tag, "upload_dir", upload_dir, sizeof(upload_dir))) continue; - if (xp.parse_bool(tag, "non_cpu_intensive", non_cpu_intensive)) continue; - if (xp.parse_bool(tag, "verify_files_on_app_start", verify_files_on_app_start)) continue; - if (xp.parse_int(tag, "homogeneous_redundancy", homogeneous_redundancy)) continue; - if (xp.parse_bool(tag, "msg_to_host", msg_to_host)) continue; - if (xp.parse_bool(tag, "ignore_upload_certificates", ignore_upload_certificates)) continue; - if (xp.parse_bool(tag, "dont_generate_upload_certificates", dont_generate_upload_certificates)) continue; - if (xp.parse_int(tag, "uldl_dir_fanout", uldl_dir_fanout)) continue; - if (xp.parse_bool(tag, "cache_md5_info", cache_md5_info)) continue; - if (xp.parse_double(tag, "fp_benchmark_weight", fp_benchmark_weight)) { + if (xp.parse_str("master_url", master_url, sizeof(master_url))) continue; + if (xp.parse_str("long_name", long_name, sizeof(long_name))) continue; + if (xp.parse_str("db_name", db_name, sizeof(db_name))) continue; + if (xp.parse_str("db_user", db_user, sizeof(db_user))) continue; + if (xp.parse_str("db_passwd", db_passwd, sizeof(db_passwd))) continue; + if (xp.parse_str("db_host", db_host, sizeof(db_host))) continue; + if (xp.parse_str("replica_db_name", replica_db_name, sizeof(replica_db_name))) continue; + if (xp.parse_str("replica_db_user", replica_db_user, sizeof(replica_db_user))) continue; + if (xp.parse_str("replica_db_passwd", replica_db_passwd, sizeof(replica_db_passwd))) continue; + if (xp.parse_str("replica_db_host", replica_db_host, sizeof(replica_db_host))) continue; + if (xp.parse_str("project_dir", project_dir, sizeof(project_dir))) continue; + if (xp.parse_int("shmem_key", shmem_key)) continue; + if (xp.parse_str("key_dir", key_dir, sizeof(key_dir))) continue; + if (xp.parse_str("download_url", download_url, sizeof(download_url))) continue; + if (xp.parse_str("download_dir", download_dir, sizeof(download_dir))) continue; + if (xp.parse_str("upload_url", upload_url, sizeof(upload_url))) continue; + if (xp.parse_str("upload_dir", upload_dir, sizeof(upload_dir))) continue; + if (xp.parse_bool("non_cpu_intensive", non_cpu_intensive)) continue; + if (xp.parse_bool("verify_files_on_app_start", verify_files_on_app_start)) continue; + if (xp.parse_int("homogeneous_redundancy", homogeneous_redundancy)) continue; + if (xp.parse_bool("msg_to_host", msg_to_host)) continue; + if (xp.parse_bool("ignore_upload_certificates", ignore_upload_certificates)) continue; + if (xp.parse_bool("dont_generate_upload_certificates", dont_generate_upload_certificates)) continue; + if (xp.parse_int("uldl_dir_fanout", uldl_dir_fanout)) continue; + if (xp.parse_bool("cache_md5_info", cache_md5_info)) continue; + if (xp.parse_double("fp_benchmark_weight", fp_benchmark_weight)) { if (fp_benchmark_weight < 0 || fp_benchmark_weight > 1) { fprintf(stderr, "CONFIG FILE ERROR: fp_benchmark_weight outside of 0..1" @@ -151,31 +154,31 @@ int SCHED_CONFIG::parse(FILE* f) { } continue; } - if (xp.parse_int(tag, "fuh_debug_level", fuh_debug_level)) continue; - if (xp.parse_int(tag, "reliable_priority_on_over", reliable_priority_on_over)) continue; - if (xp.parse_int(tag, "reliable_priority_on_over_except_error", reliable_priority_on_over_except_error)) continue; - if (xp.parse_int(tag, "reliable_on_priority", reliable_on_priority)) continue; - if (xp.parse_double(tag, "grace_period_hours", x)) { + if (xp.parse_int("fuh_debug_level", fuh_debug_level)) continue; + if (xp.parse_int("reliable_priority_on_over", reliable_priority_on_over)) continue; + if (xp.parse_int("reliable_priority_on_over_except_error", reliable_priority_on_over_except_error)) continue; + if (xp.parse_int("reliable_on_priority", reliable_on_priority)) continue; + if (xp.parse_double("grace_period_hours", x)) { report_grace_period = (int)(x*3600); continue; } - if (xp.parse_int(tag, "report_grace_period", report_grace_period)) continue; - if (xp.parse_double(tag, "delete_delay_hours", x)) { + if (xp.parse_int("report_grace_period", report_grace_period)) continue; + if (xp.parse_double("delete_delay_hours", x)) { delete_delay = x*3600; continue; } - if (xp.parse_bool(tag, "distinct_beta_apps", distinct_beta_apps)) continue; - if (xp.parse_bool(tag, "ended", ended)) continue; - if (xp.parse_int(tag, "shmem_work_items", shmem_work_items)) continue; - if (xp.parse_int(tag, "feeder_query_size", feeder_query_size)) continue; - if (xp.parse_str(tag, "httpd_user", httpd_user, sizeof(httpd_user))) continue; - if (xp.parse_bool(tag, "enable_assignment", enable_assignment)) continue; - if (xp.parse_bool(tag, "job_size_matching", job_size_matching)) continue; - if (xp.parse_bool(tag, "dont_send_jobs", dont_send_jobs)) continue; + if (xp.parse_bool("distinct_beta_apps", distinct_beta_apps)) continue; + if (xp.parse_bool("ended", ended)) continue; + if (xp.parse_int("shmem_work_items", shmem_work_items)) continue; + if (xp.parse_int("feeder_query_size", feeder_query_size)) continue; + if (xp.parse_str("httpd_user", httpd_user, sizeof(httpd_user))) continue; + if (xp.parse_bool("enable_assignment", enable_assignment)) continue; + if (xp.parse_bool("job_size_matching", job_size_matching)) continue; + if (xp.parse_bool("dont_send_jobs", dont_send_jobs)) continue; //////////// STUFF RELEVANT ONLY TO SCHEDULER STARTS HERE /////// - if (xp.parse_str(tag, "ban_cpu", buf, sizeof(buf))) { + if (xp.parse_str("ban_cpu", buf, sizeof(buf))) { retval = regcomp(&re, buf, REG_EXTENDED|REG_NOSUB); if (retval) { log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf); @@ -184,7 +187,7 @@ int SCHED_CONFIG::parse(FILE* f) { } continue; } - if (xp.parse_str(tag, "ban_os", buf, sizeof(buf))) { + if (xp.parse_str("ban_os", buf, sizeof(buf))) { retval = regcomp(&re, buf, REG_EXTENDED|REG_NOSUB); if (retval) { log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf); @@ -193,20 +196,20 @@ int SCHED_CONFIG::parse(FILE* f) { } continue; } - if (xp.parse_int(tag, "daily_result_quota", daily_result_quota)) continue; - if (xp.parse_double(tag, "default_disk_max_used_gb", default_disk_max_used_gb)) continue; - if (xp.parse_double(tag, "default_disk_max_used_pct", default_disk_max_used_pct)) continue; - if (xp.parse_double(tag, "default_disk_min_free_gb", default_disk_min_free_gb)) continue; - if (xp.parse_bool(tag, "dont_store_success_stderr", dont_store_success_stderr)) continue; - if (xp.parse_int(tag, "file_deletion_strategy", file_deletion_strategy)) continue; - if (xp.parse_int(tag, "gpu_multiplier", gpu_multiplier)) continue; - if (xp.parse_bool(tag, "ignore_delay_bound", ignore_delay_bound)) continue; - if (xp.parse_bool(tag, "locality_scheduling", locality_scheduling)) continue; - if (xp.parse_double(tag, "locality_scheduler_fraction", locality_scheduler_fraction)) continue; - if (xp.parse_bool(tag, "locality_scheduling_sorted_order", locality_scheduling_sorted_order)) continue; - if (xp.parse_int(tag, "locality_scheduling_wait_period", locality_scheduling_wait_period)) continue; - if (xp.parse_int(tag, "locality_scheduling_send_timeout", locality_scheduling_send_timeout)) continue; - if (xp.parse_str(tag, "locality_scheduling_workunit_file", buf, sizeof(buf))) { + if (xp.parse_int("daily_result_quota", daily_result_quota)) continue; + if (xp.parse_double("default_disk_max_used_gb", default_disk_max_used_gb)) continue; + if (xp.parse_double("default_disk_max_used_pct", default_disk_max_used_pct)) continue; + if (xp.parse_double("default_disk_min_free_gb", default_disk_min_free_gb)) continue; + if (xp.parse_bool("dont_store_success_stderr", dont_store_success_stderr)) continue; + if (xp.parse_int("file_deletion_strategy", file_deletion_strategy)) continue; + if (xp.parse_int("gpu_multiplier", gpu_multiplier)) continue; + if (xp.parse_bool("ignore_delay_bound", ignore_delay_bound)) continue; + if (xp.parse_bool("locality_scheduling", locality_scheduling)) continue; + if (xp.parse_double("locality_scheduler_fraction", locality_scheduler_fraction)) continue; + if (xp.parse_bool("locality_scheduling_sorted_order", locality_scheduling_sorted_order)) continue; + if (xp.parse_int("locality_scheduling_wait_period", locality_scheduling_wait_period)) continue; + if (xp.parse_int("locality_scheduling_send_timeout", locality_scheduling_send_timeout)) continue; + if (xp.parse_str("locality_scheduling_workunit_file", buf, sizeof(buf))) { retval = regcomp(&re, buf, REG_EXTENDED|REG_NOSUB); if (retval) { log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf); @@ -215,7 +218,7 @@ int SCHED_CONFIG::parse(FILE* f) { } continue; } - if (xp.parse_str(tag, "locality_scheduling_sticky_file", buf, sizeof(buf))) { + if (xp.parse_str("locality_scheduling_sticky_file", buf, sizeof(buf))) { retval = regcomp(&re, buf, REG_EXTENDED|REG_NOSUB); if (retval) { log_messages.printf(MSG_CRITICAL, "BAD REGEXP: %s\n", buf); @@ -224,20 +227,20 @@ int SCHED_CONFIG::parse(FILE* f) { } continue; } - if (xp.parse_bool(tag, "matchmaker", matchmaker)) continue; - if (xp.parse_int(tag, "max_ncpus", max_ncpus)) continue; - if (xp.parse_int(tag, "max_wus_in_progress", itemp)) { + if (xp.parse_bool("matchmaker", matchmaker)) continue; + if (xp.parse_int("max_ncpus", max_ncpus)) continue; + if (xp.parse_int("max_wus_in_progress", itemp)) { max_jobs_in_progress.project_limits.cpu.base_limit = itemp; max_jobs_in_progress.project_limits.cpu.per_proc = true; continue; } - if (xp.parse_int(tag, "max_wus_in_progress_gpu", itemp)) { + if (xp.parse_int("max_wus_in_progress_gpu", itemp)) { max_jobs_in_progress.project_limits.gpu.base_limit = itemp; max_jobs_in_progress.project_limits.gpu.per_proc = true; continue; } - if (xp.parse_int(tag, "max_wus_to_send", max_wus_to_send)) continue; - if (xp.parse_int(tag, "min_core_client_version", min_core_client_version)) { + if (xp.parse_int("max_wus_to_send", max_wus_to_send)) continue; + if (xp.parse_int("min_core_client_version", min_core_client_version)) { if (min_core_client_version && min_core_client_version < 10000) { log_messages.printf(MSG_CRITICAL, "min_core_client_version too small; multiplying by 100\n" @@ -246,7 +249,7 @@ int SCHED_CONFIG::parse(FILE* f) { } continue; } - if (xp.parse_int(tag, "min_core_client_version_announced", min_core_client_version_announced)) { + if (xp.parse_int("min_core_client_version_announced", min_core_client_version_announced)) { if (min_core_client_version_announced && min_core_client_version_announced < 10000) { log_messages.printf(MSG_CRITICAL, "min_core_client_version_announced too small; multiplying by 100\n" @@ -255,62 +258,62 @@ int SCHED_CONFIG::parse(FILE* f) { } continue; } - if (xp.parse_int(tag, "min_core_client_upgrade_deadline", min_core_client_upgrade_deadline)) continue; - if (xp.parse_int(tag, "min_sendwork_interval", min_sendwork_interval)) continue; - if (xp.parse_int(tag, "mm_min_slots", mm_min_slots)) continue; - if (xp.parse_int(tag, "mm_max_slots", mm_max_slots)) continue; - if (xp.parse_double(tag, "next_rpc_delay", next_rpc_delay)) continue; - if (xp.parse_bool(tag, "no_amd_k6", no_amd_k6)) { + if (xp.parse_int("min_core_client_upgrade_deadline", min_core_client_upgrade_deadline)) continue; + if (xp.parse_int("min_sendwork_interval", min_sendwork_interval)) continue; + if (xp.parse_int("mm_min_slots", mm_min_slots)) continue; + if (xp.parse_int("mm_max_slots", mm_max_slots)) continue; + if (xp.parse_double("next_rpc_delay", next_rpc_delay)) continue; + if (xp.parse_bool("no_amd_k6", no_amd_k6)) { if (no_amd_k6) { regcomp(&re, ".*AMD.*\t.*Family 5 Model 8 Stepping 0.*", REG_EXTENDED|REG_NOSUB); ban_cpu->push_back(re); } continue; } - if (xp.parse_bool(tag, "no_vista_sandbox", no_vista_sandbox)) continue; - if (xp.parse_bool(tag, "nowork_skip", nowork_skip)) continue; - if (xp.parse_bool(tag, "one_result_per_host_per_wu", one_result_per_host_per_wu)) continue; - if (xp.parse_bool(tag, "one_result_per_user_per_wu", one_result_per_user_per_wu)) continue; - if (xp.parse_int(tag, "reliable_max_avg_turnaround", reliable_max_avg_turnaround)) continue; - if (xp.parse_double(tag, "reliable_max_error_rate", reliable_max_error_rate)) continue; - if (xp.parse_double(tag, "reliable_reduced_delay_bound", reliable_reduced_delay_bound)) continue; - if (xp.parse_str(tag, "replace_download_url_by_timezone", replace_download_url_by_timezone, sizeof(replace_download_url_by_timezone))) continue; - if (xp.parse_int(tag, "max_download_urls_per_file", max_download_urls_per_file)) continue; - if (xp.parse_int(tag, "report_max", report_max)) continue; - if (xp.parse_bool(tag, "request_time_stats_log", request_time_stats_log)) continue; - if (xp.parse_bool(tag, "resend_lost_results", resend_lost_results)) continue; - if (xp.parse_int(tag, "sched_debug_level", sched_debug_level)) continue; - if (xp.parse_str(tag, "sched_lockfile_dir", sched_lockfile_dir, sizeof(sched_lockfile_dir))) continue; - if (xp.parse_bool(tag, "send_result_abort", send_result_abort)) continue; - if (xp.parse_str(tag, "symstore", symstore, sizeof(symstore))) continue; + if (xp.parse_bool("no_vista_sandbox", no_vista_sandbox)) continue; + if (xp.parse_bool("nowork_skip", nowork_skip)) continue; + if (xp.parse_bool("one_result_per_host_per_wu", one_result_per_host_per_wu)) continue; + if (xp.parse_bool("one_result_per_user_per_wu", one_result_per_user_per_wu)) continue; + if (xp.parse_int("reliable_max_avg_turnaround", reliable_max_avg_turnaround)) continue; + if (xp.parse_double("reliable_max_error_rate", reliable_max_error_rate)) continue; + if (xp.parse_double("reliable_reduced_delay_bound", reliable_reduced_delay_bound)) continue; + if (xp.parse_str("replace_download_url_by_timezone", replace_download_url_by_timezone, sizeof(replace_download_url_by_timezone))) continue; + if (xp.parse_int("max_download_urls_per_file", max_download_urls_per_file)) continue; + if (xp.parse_int("report_max", report_max)) continue; + if (xp.parse_bool("request_time_stats_log", request_time_stats_log)) continue; + if (xp.parse_bool("resend_lost_results", resend_lost_results)) continue; + if (xp.parse_int("sched_debug_level", sched_debug_level)) continue; + if (xp.parse_str("sched_lockfile_dir", sched_lockfile_dir, sizeof(sched_lockfile_dir))) continue; + if (xp.parse_bool("send_result_abort", send_result_abort)) continue; + if (xp.parse_str("symstore", symstore, sizeof(symstore))) continue; - if (xp.parse_bool(tag, "user_filter", user_filter)) continue; - if (xp.parse_bool(tag, "workload_sim", workload_sim)) continue; - if (xp.parse_bool(tag, "prefer_primary_platform", prefer_primary_platform)) continue; + if (xp.parse_bool("user_filter", user_filter)) continue; + if (xp.parse_bool("workload_sim", workload_sim)) continue; + if (xp.parse_bool("prefer_primary_platform", prefer_primary_platform)) continue; //////////// SCHEDULER LOG FLAGS ///////// - if (xp.parse_bool(tag, "debug_array", debug_array)) continue; - if (xp.parse_bool(tag, "debug_assignment", debug_assignment)) continue; - if (xp.parse_bool(tag, "debug_credit", debug_credit)) continue; - if (xp.parse_bool(tag, "debug_edf_sim_detail", debug_edf_sim_detail)) continue; - if (xp.parse_bool(tag, "debug_edf_sim_workload", debug_edf_sim_workload)) continue; - if (xp.parse_bool(tag, "debug_fcgi", debug_fcgi)) continue; - if (xp.parse_bool(tag, "debug_handle_results", debug_handle_results)) continue; - if (xp.parse_bool(tag, "debug_locality", debug_locality)) continue; - if (xp.parse_bool(tag, "debug_prefs", debug_prefs)) continue; - if (xp.parse_bool(tag, "debug_quota", debug_quota)) continue; - if (xp.parse_bool(tag, "debug_request_details", debug_request_details)) continue; - if (xp.parse_bool(tag, "debug_request_headers", debug_request_headers)) continue; - if (xp.parse_bool(tag, "debug_resend", debug_resend)) continue; - if (xp.parse_bool(tag, "debug_send", debug_send)) continue; - if (xp.parse_bool(tag, "debug_user_messages", debug_user_messages)) continue; - if (xp.parse_bool(tag, "debug_version_select", debug_version_select)) continue; + if (xp.parse_bool("debug_array", debug_array)) continue; + if (xp.parse_bool("debug_assignment", debug_assignment)) continue; + if (xp.parse_bool("debug_credit", debug_credit)) continue; + if (xp.parse_bool("debug_edf_sim_detail", debug_edf_sim_detail)) continue; + if (xp.parse_bool("debug_edf_sim_workload", debug_edf_sim_workload)) continue; + if (xp.parse_bool("debug_fcgi", debug_fcgi)) continue; + if (xp.parse_bool("debug_handle_results", debug_handle_results)) continue; + if (xp.parse_bool("debug_locality", debug_locality)) continue; + if (xp.parse_bool("debug_prefs", debug_prefs)) continue; + if (xp.parse_bool("debug_quota", debug_quota)) continue; + if (xp.parse_bool("debug_request_details", debug_request_details)) continue; + if (xp.parse_bool("debug_request_headers", debug_request_headers)) continue; + if (xp.parse_bool("debug_resend", debug_resend)) continue; + if (xp.parse_bool("debug_send", debug_send)) continue; + if (xp.parse_bool("debug_user_messages", debug_user_messages)) continue; + if (xp.parse_bool("debug_version_select", debug_version_select)) continue; // don't complain about unparsed XML; // there are lots of tags the scheduler doesn't know about - xp.skip_unexpected(tag, false, "SCHED_CONFIG::parse"); + xp.skip_unexpected(false, "SCHED_CONFIG::parse"); } return ERR_XML_PARSE; } diff --git a/sched/sched_limit.cpp b/sched/sched_limit.cpp index bf58233b84..80cf819ed8 100644 --- a/sched/sched_limit.cpp +++ b/sched/sched_limit.cpp @@ -21,21 +21,18 @@ #include "sched_limit.h" int RSC_JOB_LIMIT::parse(XML_PARSER& xp, const char* end_tag) { - char tag[1024]; - bool is_tag; - per_proc = false; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { continue; } - if (!strcmp(tag, end_tag)) { + if (xp.match_tag(end_tag)) { return 0; } - if (xp.parse_int(tag, "jobs", base_limit)) { + if (xp.parse_int("jobs", base_limit)) { continue; } - if (xp.parse_bool(tag, "per_proc", per_proc)) { + if (xp.parse_bool("per_proc", per_proc)) { continue; } } @@ -43,28 +40,25 @@ int RSC_JOB_LIMIT::parse(XML_PARSER& xp, const char* end_tag) { } int JOB_LIMIT::parse(XML_PARSER& xp, const char* end_tag) { - char tag[1024]; - bool is_tag; - - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { continue; } - if (!strcmp(tag, end_tag)) { + if (xp.match_tag(end_tag)) { return 0; } - if (xp.parse_str(tag, "app_name", app_name, sizeof(app_name))) { + if (xp.parse_str("app_name", app_name, sizeof(app_name))) { continue; } - if (!strcmp(tag, "total_limit")) { + if (xp.match_tag("total_limit")) { total.parse(xp, "/total_limit"); continue; } - if (!strcmp(tag, "cpu_limit")) { + if (xp.match_tag("cpu_limit")) { cpu.parse(xp, "/cpu_limit"); continue; } - if (!strcmp(tag, "gpu_limit")) { + if (xp.match_tag("gpu_limit")) { gpu.parse(xp, "/gpu_limit"); continue; } @@ -73,21 +67,18 @@ int JOB_LIMIT::parse(XML_PARSER& xp, const char* end_tag) { } int JOB_LIMITS::parse(XML_PARSER& xp, const char* end_tag) { - char tag[1024]; - bool is_tag; - - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) { + while (!xp.get_tag()) { + if (!xp.is_tag) { continue; } - if (!strcmp(tag, end_tag)) { + if (xp.match_tag(end_tag)) { return 0; } - if (!strcmp(tag, "project")) { + if (xp.match_tag("project")) { project_limits.parse(xp, "/project"); continue; } - if (!strcmp(tag, "app")) { + if (xp.match_tag("app")) { JOB_LIMIT jl; jl.parse(xp, "/app"); if (!strlen(jl.app_name)) { diff --git a/sched/sched_types.cpp b/sched/sched_types.cpp index 11a971a5c1..730a4b0874 100644 --- a/sched/sched_types.cpp +++ b/sched/sched_types.cpp @@ -57,13 +57,14 @@ void remove_quotes(char* p) { } } -int CLIENT_APP_VERSION::parse(FILE* f) { +int CLIENT_APP_VERSION::parse(XML_PARSER& xp) { char buf[256]; double x; memset(this, 0, sizeof(*this)); host_usage.avg_ncpus = 1; - while (fgets(buf, sizeof(buf), f)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) { app = ssp->lookup_app_name(app_name); if (!app) return ERR_NOT_FOUND; @@ -92,9 +93,7 @@ int CLIENT_APP_VERSION::parse(FILE* f) { } if (match_tag(buf, "")) { COPROC_REQ coproc_req; - MIOFILE mf; - mf.init_file(f); - int retval = coproc_req.parse(mf); + int retval = coproc_req.parse(xp); if (!retval && !strcmp(coproc_req.type, "CUDA")) { host_usage.ncudas = coproc_req.count; } @@ -107,11 +106,12 @@ int CLIENT_APP_VERSION::parse(FILE* f) { return ERR_XML_PARSE; } -int FILE_INFO::parse(FILE* f) { +int FILE_INFO::parse(XML_PARSER& xp) { char buf[256]; memset(this, 0, sizeof(*this)); - while (fgets(buf, sizeof(buf), f)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) { if (!strlen(name)) return ERR_XML_PARSE; return 0; @@ -121,13 +121,14 @@ int FILE_INFO::parse(FILE* f) { return ERR_XML_PARSE; } -int OTHER_RESULT::parse(FILE* f) { +int OTHER_RESULT::parse(XML_PARSER& xp) { char buf[256]; strcpy(name, ""); have_plan_class = false; app_version = -1; - while (fgets(buf, sizeof(buf), f)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) { if (!strcmp(name, "")) return ERR_XML_PARSE; return 0; @@ -142,13 +143,14 @@ int OTHER_RESULT::parse(FILE* f) { return ERR_XML_PARSE; } -int IP_RESULT::parse(FILE* f) { +int IP_RESULT::parse(XML_PARSER& xp) { char buf[256]; report_deadline = 0; cpu_time_remaining = 0; strcpy(name, ""); - while (fgets(buf, sizeof(buf), f)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) return 0; if (parse_str(buf, "", name, sizeof(name))) continue; if (parse_double(buf, "", report_deadline)) continue; @@ -157,10 +159,11 @@ int IP_RESULT::parse(FILE* f) { return ERR_XML_PARSE; } -int CLIENT_PLATFORM::parse(FILE* fin) { +int CLIENT_PLATFORM::parse(XML_PARSER& xp) { char buf[256]; strcpy(name, ""); - while (fgets(buf, sizeof(buf), fin)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) return 0; if (parse_str(buf, "", name, sizeof(name))) continue; } @@ -179,7 +182,7 @@ void WORK_REQ::add_no_work_message(const char* message) { // return an error message or NULL // -const char* SCHEDULER_REQUEST::parse(FILE* fin) { +const char* SCHEDULER_REQUEST::parse(XML_PARSER& xp) { char buf[256]; SCHED_DB_RESULT result; int retval; @@ -213,20 +216,21 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { // TODO: use XML_PARSER FOR THIS - if (!fgets(buf, sizeof(buf), fin)) { + MIOFILE& in = *(xp.f); + if (!in.fgets(buf, sizeof(buf))) { return "fgets() failed"; } if (strstr(buf, "")) return "no start tag"; - while (fgets(buf, sizeof(buf), fin)) { + while (in.fgets(buf, sizeof(buf))) { // If a line is too long, ignore it. // This can happen e.g. if the client has bad global_prefs.xml // This won't be necessary if we rewrite this using XML_PARSER // if (!strchr(buf, '\n')) { - while (fgets(buf, sizeof(buf), fin)) { + while (in.fgets(buf, sizeof(buf))) { if (strchr(buf, '\n')) break; } continue; @@ -246,18 +250,18 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { if (parse_str(buf, "", platform.name, sizeof(platform.name))) continue; if (match_tag(buf, "")) { CLIENT_PLATFORM cp; - retval = cp.parse(fin); + retval = cp.parse(xp); if (!retval) { alt_platforms.push_back(cp); } continue; } if (match_tag(buf, "")) { - while (fgets(buf, sizeof(buf), fin)) { + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) break; if (match_tag(buf, "")) { CLIENT_APP_VERSION cav; - retval = cav.parse(fin); + retval = cav.parse(xp); if (retval) { if (!strcmp(platform.name, "anonymous")) { if (retval == ERR_NOT_FOUND) { @@ -299,7 +303,7 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { if (parse_double(buf, "", host.duration_correction_factor)) continue; if (match_tag(buf, "")) { strcpy(global_prefs_xml, "\n"); - while (fgets(buf, sizeof(buf), fin)) { + while (in.fgets(buf, sizeof(buf))) { if (strstr(buf, "")) break; safe_strcat(global_prefs_xml, buf); } @@ -307,7 +311,7 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { continue; } if (match_tag(buf, "")) { - while (fgets(buf, sizeof(buf), fin)) { + while (in.fgets(buf, sizeof(buf))) { if (strstr(buf, "")) break; safe_strcat(working_global_prefs_xml, buf); } @@ -315,28 +319,28 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { } if (parse_str(buf, "", global_prefs_source_email_hash, sizeof(global_prefs_source_email_hash))) continue; if (match_tag(buf, "")) { - host.parse(fin); + host.parse(xp); continue; } if (match_tag(buf, "")) { - host.parse_time_stats(fin); + host.parse_time_stats(xp); continue; } if (match_tag(buf, "")) { - handle_time_stats_log(fin); + handle_time_stats_log(xp.f->f); have_time_stats_log = true; continue; } if (match_tag(buf, "")) { - host.parse_net_stats(fin); + host.parse_net_stats(xp); continue; } if (match_tag(buf, "")) { - host.parse_disk_usage(fin); + host.parse_disk_usage(xp); continue; } if (match_tag(buf, "")) { - retval = result.parse_from_client(fin); + retval = result.parse_from_client(xp); if (retval) continue; if (strstr(result.name, "download") || strstr(result.name, "upload")) { file_xfer_results.push_back(result); @@ -363,12 +367,12 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { continue; } if (match_tag(buf, "")) { - copy_element_contents(fin, "", code_sign_key, sizeof(code_sign_key)); + copy_element_contents(in.f, "", code_sign_key, sizeof(code_sign_key)); continue; } if (match_tag(buf, "")) { MSG_FROM_HOST_DESC md; - retval = md.parse(fin); + retval = md.parse(xp); if (!retval) { msgs_from_host.push_back(md); } @@ -376,7 +380,7 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { } if (match_tag(buf, "")) { FILE_INFO fi; - retval = fi.parse(fin); + retval = fi.parse(xp); if (!retval) { file_infos.push_back(fi); } @@ -387,11 +391,11 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { } if (match_tag(buf, "")) { have_other_results_list = true; - while (fgets(buf, sizeof(buf), fin)) { + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) break; if (match_tag(buf, "")) { OTHER_RESULT o_r; - retval = o_r.parse(fin); + retval = o_r.parse(xp); if (!retval) { other_results.push_back(o_r); } @@ -403,11 +407,11 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { have_ip_results_list = true; int i = 0; double now = time(0); - while (fgets(buf, sizeof(buf), fin)) { + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) break; if (match_tag(buf, "")) { IP_RESULT ir; - retval = ir.parse(fin); + retval = ir.parse(xp); if (!retval) { if (!strlen(ir.name)) { sprintf(ir.name, "ip%d", i++); @@ -420,9 +424,7 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { continue; } if (match_tag(buf, "coprocs")) { - MIOFILE mf; - mf.init_file(fin); - coprocs.parse(mf); + coprocs.parse(xp); continue; } if (parse_bool(buf, "client_cap_plan_class", client_cap_plan_class)) continue; @@ -466,9 +468,7 @@ const char* SCHEDULER_REQUEST::parse(FILE* fin) { log_messages.printf(MSG_NORMAL, "SCHEDULER_REQUEST::parse(): unrecognized: %s\n", buf ); - MIOFILE mf; - mf.init_file(fin); - retval = skip_unrecognized(buf, mf); + retval = skip_unrecognized(buf, in); if (retval) return "unterminated unrecognized XML"; } return "no end tag"; @@ -597,11 +597,12 @@ int SCHEDULER_REQUEST::write(FILE* fout) { return 0; } -int MSG_FROM_HOST_DESC::parse(FILE* fin) { +int MSG_FROM_HOST_DESC::parse(XML_PARSER& xp) { char buf[256]; msg_text = ""; - while (fgets(buf, sizeof(buf), fin)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) return 0; if (parse_str(buf, "", variety, sizeof(variety))) continue; msg_text += buf; @@ -1094,13 +1095,14 @@ int SCHED_DB_RESULT::write_to_client(FILE* fout) { return 0; } -int SCHED_DB_RESULT::parse_from_client(FILE* fin) { +int SCHED_DB_RESULT::parse_from_client(XML_PARSER& xp) { char buf[256]; // should be non-zero if exit_status is not found exit_status = ERR_NO_EXIT_STATUS; memset(this, 0, sizeof(*this)); - while (fgets(buf, sizeof(buf), fin)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) { return 0; } @@ -1116,14 +1118,14 @@ int SCHED_DB_RESULT::parse_from_client(FILE* fin) { if (parse_double(buf, "", intops_cumulative)) continue; if (match_tag(buf, "")) { safe_strcat(xml_doc_out, buf); - while (fgets(buf, sizeof(buf), fin)) { + while (in.fgets(buf, sizeof(buf))) { safe_strcat(xml_doc_out, buf); if (match_tag(buf, "")) break; } continue; } if (match_tag(buf, "" )) { - while (fgets(buf, sizeof(buf), fin)) { + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) break; safe_strcat(stderr_out, buf); } @@ -1150,11 +1152,12 @@ int SCHED_DB_RESULT::parse_from_client(FILE* fin) { return ERR_XML_PARSE; } -int HOST::parse(FILE* fin) { +int HOST::parse(XML_PARSER& xp) { char buf[1024]; p_ncpus = 1; - while (fgets(buf, sizeof(buf), fin)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) return 0; if (parse_int(buf, "", timezone)) continue; if (parse_str(buf, "", domain_name, sizeof(domain_name))) continue; @@ -1207,10 +1210,11 @@ int HOST::parse(FILE* fin) { } -int HOST::parse_time_stats(FILE* fin) { +int HOST::parse_time_stats(XML_PARSER& xp) { char buf[256]; - while (fgets(buf, sizeof(buf), fin)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) return 0; if (parse_double(buf, "", on_frac)) continue; if (parse_double(buf, "", connected_frac)) continue; @@ -1229,10 +1233,11 @@ int HOST::parse_time_stats(FILE* fin) { return ERR_XML_PARSE; } -int HOST::parse_net_stats(FILE* fin) { +int HOST::parse_net_stats(XML_PARSER& xp) { char buf[256]; - while (fgets(buf, sizeof(buf), fin)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) return 0; if (parse_double(buf, "", n_bwup)) continue; if (parse_double(buf, "", n_bwdown)) continue; @@ -1252,10 +1257,11 @@ int HOST::parse_net_stats(FILE* fin) { return ERR_XML_PARSE; } -int HOST::parse_disk_usage(FILE* fin) { +int HOST::parse_disk_usage(XML_PARSER& xp) { char buf[256]; - while (fgets(buf, sizeof(buf), fin)) { + MIOFILE& in = *(xp.f); + while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "")) return 0; if (parse_double(buf, "", d_boinc_used_total)) continue; if (parse_double(buf, "", d_boinc_used_project)) continue; diff --git a/sched/sched_types.h b/sched/sched_types.h index dcccad3c3a..df55634788 100644 --- a/sched/sched_types.h +++ b/sched/sched_types.h @@ -129,13 +129,13 @@ struct HOST_USAGE { struct FILE_INFO { char name[256]; - int parse(FILE*); + int parse(XML_PARSER&); }; struct MSG_FROM_HOST_DESC { char variety[256]; std::string msg_text; - int parse(FILE*); + int parse(XML_PARSER&); }; // an app version from an anonymous-platform client @@ -156,7 +156,7 @@ struct CLIENT_APP_VERSION { // if NULL, this record is a place-holder, // used to preserve array indices - int parse(FILE*); + int parse(XML_PARSER&); }; // keep track of the best app_version for each app for this host @@ -201,7 +201,7 @@ struct SCHED_DB_RESULT : DB_RESULT { double intops_per_cpu_sec; double intops_cumulative; int units; // used for granting credit by # of units processed - int parse_from_client(FILE*); + int parse_from_client(XML_PARSER&); char platform_name[256]; BEST_APP_VERSION bav; @@ -250,7 +250,7 @@ struct OTHER_RESULT { bool abort_if_not_started; int reason; // see codes below - int parse(FILE*); + int parse(XML_PARSER&); }; #define ABORT_REASON_NOT_FOUND 1 @@ -260,7 +260,7 @@ struct OTHER_RESULT { struct CLIENT_PLATFORM { char name[256]; - int parse(FILE*); + int parse(XML_PARSER&); }; struct PLATFORM_LIST { @@ -334,7 +334,7 @@ struct SCHEDULER_REQUEST { SCHEDULER_REQUEST(){}; ~SCHEDULER_REQUEST(){}; - const char* parse(FILE*); + const char* parse(XML_PARSER&); int write(FILE*); // write request info to file: not complete }; diff --git a/sched/trickle_credit.cpp b/sched/trickle_credit.cpp index a44dfa055c..31bdefdd0a 100644 --- a/sched/trickle_credit.cpp +++ b/sched/trickle_credit.cpp @@ -35,16 +35,14 @@ int handle_trickle(MSG_FROM_HOST& msg) { double cpu_time = 0; - char tag[256]; - bool is_tag; MIOFILE mf; mf.init_buf_read(msg.xml); XML_PARSER xp(&mf); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (xp.parse_double(tag, "cpu_time", cpu_time)) break; - log_messages.printf(MSG_NORMAL, "unexpected tag: %s\n", tag); + while (!xp.get_tag()) { + if (xp.parse_double("cpu_time", cpu_time)) break; + log_messages.printf(MSG_NORMAL, "unexpected tag: %s\n", xp.parsed_tag); } if (!cpu_time) { log_messages.printf(MSG_NORMAL, "unexpected zero CPU time\n"); diff --git a/sched/validate_util.cpp b/sched/validate_util.cpp index 618f7bbbb5..4aa710d7cd 100644 --- a/sched/validate_util.cpp +++ b/sched/validate_util.cpp @@ -40,35 +40,33 @@ using std::string; ////////// functions for locating output files /////////////// int FILE_INFO::parse(XML_PARSER& xp) { - char tag[256]; - bool is_tag, found=false; + bool found=false; optional = false; no_validate = false; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/file_ref")) { + 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(tag, "file_name", name)) { + if (xp.parse_string("file_name", name)) { found = true; continue; } - if (xp.parse_bool(tag, "optional", optional)) continue; - if (xp.parse_bool(tag, "no_validate", no_validate)) 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, FILE_INFO& fi) { - char tag[256], path[1024]; - bool is_tag; + char path[1024]; string name; MIOFILE mf; mf.init_buf_read(result.xml_doc_in); XML_PARSER xp(&mf); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "file_ref")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("file_ref")) { int retval = fi.parse(xp); if (retval) return retval; dir_hier_path( @@ -82,16 +80,15 @@ int get_output_file_info(RESULT& result, FILE_INFO& fi) { } int get_output_file_infos(RESULT& result, vector& fis) { - char tag[256], path[1024]; - bool is_tag; + char path[1024]; MIOFILE mf; string name; mf.init_buf_read(result.xml_doc_in); XML_PARSER xp(&mf); fis.clear(); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "file_ref")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("file_ref")) { FILE_INFO fi; int retval = fi.parse(xp); if (retval) return retval; @@ -128,18 +125,15 @@ struct FILE_REF { char file_name[256]; char open_name[256]; int parse(XML_PARSER& xp) { - char tag[256]; - 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")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_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; + if (xp.parse_str("file_name", file_name, sizeof(file_name))) continue; + if (xp.parse_str("open_name", open_name, sizeof(open_name))) continue; } return ERR_XML_PARSE; } @@ -149,8 +143,6 @@ struct FILE_REF { // int get_logical_name(RESULT& result, string& path, string& name) { char phys_name[1024]; - char tag[256]; - bool is_tag; MIOFILE mf; int retval; @@ -162,10 +154,10 @@ int get_logical_name(RESULT& result, string& path, string& 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")) { + while (!xp.get_tag()) { + if (!xp.is_tag) continue; + if (xp.match_tag("result")) continue; + if (xp.match_tag("file_ref")) { FILE_REF fr; retval = fr.parse(xp); if (retval) continue; @@ -175,7 +167,7 @@ int get_logical_name(RESULT& result, string& path, string& name) { } continue; } - xp.skip_unexpected(tag, false, 0); + xp.skip_unexpected(false, 0); } return ERR_XML_PARSE; } diff --git a/tools/backend_lib.cpp b/tools/backend_lib.cpp index a5ee2e00e7..9b7076c2fa 100644 --- a/tools/backend_lib.cpp +++ b/tools/backend_lib.cpp @@ -197,32 +197,30 @@ static int process_wu_template( out = ""; MIOFILE mf; XML_PARSER xp(&mf); - char tag[256]; - bool is_tag; mf.init_buf_read(tmplate); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "input_template")) continue; - if (!strcmp(tag, "/input_template")) continue; - if (!strcmp(tag, "file_info")) { + 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 urls; bool generated_locally = false; file_number = nbytesdef = -1; md5str = urlstr = ""; out += "\n"; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (xp.parse_int(tag, "number", file_number)) { + while (!xp.get_tag()) { + if (xp.parse_int("number", file_number)) { continue; - } else if (xp.parse_bool(tag, "generated_locally", generated_locally)) { + } else if (xp.parse_bool("generated_locally", generated_locally)) { continue; - } else if (xp.parse_string(tag, "url", urlstr)) { + } else if (xp.parse_string("url", urlstr)) { urls.push_back(urlstr); continue; - } else if (xp.parse_string(tag, "md5_cksum", md5str)) { + } else if (xp.parse_string("md5_cksum", md5str)) { continue; - } else if (xp.parse_double(tag, "nbytes", nbytesdef)) { + } else if (xp.parse_double("nbytes", nbytesdef)) { continue; - } else if (!strcmp(tag, "/file_info")) { + } else if (xp.match_tag("/file_info")) { if (nbytesdef != -1 || md5str != "" || urlstr != "") { if (nbytesdef == -1 || md5str == "" || urlstr == "") { fprintf(stderr, "All file properties must be defined " @@ -318,13 +316,13 @@ static int process_wu_template( break; } else { char buf2[1024]; - retval = xp.element(tag, buf2, sizeof(buf2)); + retval = xp.element(xp.parsed_tag, buf2, sizeof(buf2)); if (retval) return retval; out += buf2; out += "\n"; } } - } else if (!strcmp(tag, "workunit")) { + } else if (xp.match_tag("workunit")) { found = true; out += "\n"; if (command_line) { @@ -333,31 +331,31 @@ static int process_wu_template( out += command_line; out += "\n\n"; } - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!strcmp(tag, "/workunit")) { + while (!xp.get_tag()) { + if (xp.match_tag("/workunit")) { if (additional_xml && strlen(additional_xml)) { out += additional_xml; out += "\n"; } out += "\n"; break; - } else if (!strcmp(tag, "file_ref")) { + } else if (xp.match_tag("file_ref")) { out += "\n"; bool found_file_number = false, found_open_name = false; - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (xp.parse_int(tag, "file_number", file_number)) { + while (!xp.get_tag()) { + if (xp.parse_int("file_number", file_number)) { sprintf(buf, " %s\n", infiles[file_number] ); out += buf; found_file_number = true; continue; - } else if (xp.parse_str(tag, "open_name", open_name, sizeof(open_name))) { + } else if (xp.parse_str("open_name", open_name, sizeof(open_name))) { sprintf(buf, " %s\n", open_name); out += buf; found_open_name = true; continue; - } else if (!strcmp(tag, "/file_ref")) { + } else if (xp.match_tag("/file_ref")) { if (!found_file_number) { fprintf(stderr, "No file number found\n"); return ERR_XML_PARSE; @@ -368,18 +366,18 @@ static int process_wu_template( } out += "\n"; break; - } else if (xp.parse_string(tag, "file_name", tmpstr)) { + } else if (xp.parse_string("file_name", tmpstr)) { fprintf(stderr, " ignored in element.\n"); continue; } else { char buf2[1024]; - retval = xp.element(tag, buf2, sizeof(buf2)); + retval = xp.element(xp.parsed_tag, buf2, sizeof(buf2)); if (retval) return retval; out += buf2; out += "\n"; } } - } else if (xp.parse_string(tag, "command_line", cmdline)) { + } else if (xp.parse_string("command_line", cmdline)) { if (command_line) { fprintf(stderr, "Can't specify command line twice"); return ERR_XML_PARSE; @@ -387,51 +385,51 @@ static int process_wu_template( out += "\n"; out += cmdline; out += "\n\n"; - } else if (xp.parse_double(tag, "rsc_fpops_est", dtemp)) { + } else if (xp.parse_double("rsc_fpops_est", dtemp)) { if (!wu.rsc_fpops_est) { wu.rsc_fpops_est = dtemp; } continue; - } else if (xp.parse_double(tag, "rsc_fpops_bound", dtemp)) { + } else if (xp.parse_double("rsc_fpops_bound", dtemp)) { if (!wu.rsc_fpops_bound) { wu.rsc_fpops_bound = dtemp; } continue; - } else if (xp.parse_double(tag, "rsc_memory_bound", dtemp)) { + } else if (xp.parse_double("rsc_memory_bound", dtemp)) { if (!wu.rsc_memory_bound) { wu.rsc_memory_bound = dtemp; } continue; - } else if (xp.parse_double(tag, "rsc_bandwidth_bound", dtemp)) { + } else if (xp.parse_double("rsc_bandwidth_bound", dtemp)) { if (!wu.rsc_bandwidth_bound) { wu.rsc_bandwidth_bound = dtemp; } continue; - } else if (xp.parse_double(tag, "rsc_disk_bound", dtemp)) { + } else if (xp.parse_double("rsc_disk_bound", dtemp)) { if (!wu.rsc_disk_bound) { wu.rsc_disk_bound = dtemp; } continue; - } else if (xp.parse_int(tag, "batch", wu.batch)) { + } else if (xp.parse_int("batch", wu.batch)) { continue; - } else if (xp.parse_int(tag, "delay_bound", itemp)) { + } else if (xp.parse_int("delay_bound", itemp)) { if (!wu.delay_bound) { wu.delay_bound = itemp; } continue; - } else if (xp.parse_int(tag, "min_quorum", wu.min_quorum)) { + } else if (xp.parse_int("min_quorum", wu.min_quorum)) { continue; - } else if (xp.parse_int(tag, "target_nresults", wu.target_nresults)) { + } else if (xp.parse_int("target_nresults", wu.target_nresults)) { continue; - } else if (xp.parse_int(tag, "max_error_results", wu.max_error_results)) { + } else if (xp.parse_int("max_error_results", wu.max_error_results)) { continue; - } else if (xp.parse_int(tag, "max_total_results", wu.max_total_results)) { + } else if (xp.parse_int("max_total_results", wu.max_total_results)) { continue; - } else if (xp.parse_int(tag, "max_success_results", wu.max_success_results)) { + } else if (xp.parse_int("max_success_results", wu.max_success_results)) { continue; } else { char buf2[1024]; - retval = xp.element(tag, buf2, sizeof(buf2)); + retval = xp.element(xp.parsed_tag, buf2, sizeof(buf2)); if (retval) return retval; out += buf2; out += "\n"; @@ -747,8 +745,8 @@ int get_file( "\n" " %s\n" " %.0f\n", - max_nbytes, - file_name + file_name, + max_nbytes ); for (unsigned int i=0; i%s\n", urls[i]);