Beispiel #1
0
// return an error message or NULL
//
const char* SCHEDULER_REQUEST::parse(XML_PARSER& xp) {
    SCHED_DB_RESULT result;
    int retval;

    strcpy(authenticator, "");
    strcpy(platform.name, "");
    strcpy(cross_project_id, "");
    hostid = 0;
    core_client_major_version = 0;
    core_client_minor_version = 0;
    core_client_release = 0;
    core_client_version = 0;
    rpc_seqno = 0;
    work_req_seconds = 0;
    cpu_req_secs = 0;
    cpu_req_instances = 0;
    resource_share_fraction = 1.0;
    rrs_fraction = 1.0;
    prrs_fraction = 1.0;
    cpu_estimated_delay = 0;
    strcpy(global_prefs_xml, "");
    strcpy(working_global_prefs_xml, "");
    strcpy(code_sign_key, "");
    memset(&global_prefs, 0, sizeof(global_prefs));
    memset(&host, 0, sizeof(host));
    have_other_results_list = false;
    have_ip_results_list = false;
    have_time_stats_log = false;
    client_cap_plan_class = false;
    sandbox = -1;
    allow_multiple_clients = -1;

    if (xp.get_tag()) {
        return "xp.get_tag() failed";
    }
    if (xp.match_tag("?xml")) {
        xp.get_tag();
    }
    if (!xp.match_tag("scheduler_request")) return "no start tag";
    while (!xp.get_tag()) {
        if (xp.match_tag("/scheduler_request")) {
            core_client_version = 10000*core_client_major_version + 100*core_client_minor_version + core_client_release;
            return NULL;
        }
        if (xp.parse_str("authenticator", authenticator, sizeof(authenticator))) {
            remove_quotes(authenticator);
            continue;
        }
        if (xp.parse_str("cross_project_id", cross_project_id, sizeof(cross_project_id))) continue;
        if (xp.parse_int("hostid", hostid)) continue;
        if (xp.parse_int("rpc_seqno", rpc_seqno)) continue;
        if (xp.parse_str("platform_name", platform.name, sizeof(platform.name))) continue;
        if (xp.match_tag("alt_platform")) {
            CLIENT_PLATFORM cp;
            retval = cp.parse(xp);
            if (!retval) {
                alt_platforms.push_back(cp);
            }
            continue;
        }
        if (xp.match_tag("app_versions")) {
            while (!xp.get_tag()) {
                if (xp.match_tag("/app_versions")) break;
                if (xp.match_tag("app_version")) {
                    CLIENT_APP_VERSION cav;
                    retval = cav.parse(xp);
                    if (retval) {
                        if (!strcmp(platform.name, "anonymous")) {
                            if (retval == ERR_NOT_FOUND) {
                                g_reply->insert_message(
                                    _("Unknown app name in app_info.xml"),
                                    "notice"
                                );
                            } else {
                                g_reply->insert_message(
                                    _("Syntax error in app_info.xml"),
                                    "notice"
                                );
                            }
                        } else {
                            // this case happens if the app version
                            // refers to a deprecated app
                        }
                        cav.app = 0;
                    }
                    // store the CLIENT_APP_VERSION even if it didn't parse.
                    // This is necessary to maintain the correspondence
                    // with result.app_version
                    //
                    client_app_versions.push_back(cav);
                }
            }
            continue;
        }
        if (xp.parse_int("core_client_major_version", core_client_major_version)) continue;
        if (xp.parse_int("core_client_minor_version", core_client_minor_version)) continue;
        if (xp.parse_int("core_client_release", core_client_release)) continue;
        if (xp.parse_double("work_req_seconds", work_req_seconds)) continue;
        if (xp.parse_double("cpu_req_secs", cpu_req_secs)) continue;
        if (xp.parse_double("cpu_req_instances", cpu_req_instances)) continue;
        if (xp.parse_double("resource_share_fraction", resource_share_fraction)) continue;
        if (xp.parse_double("rrs_fraction", rrs_fraction)) continue;
        if (xp.parse_double("prrs_fraction", prrs_fraction)) continue;
        if (xp.parse_double("estimated_delay", cpu_estimated_delay)) continue;
        if (xp.parse_double("duration_correction_factor", host.duration_correction_factor)) continue;
        if (xp.match_tag("global_preferences")) {
            strcpy(global_prefs_xml, "<global_preferences>\n");
            char buf[BLOB_SIZE];
            retval = xp.element_contents(
                "</global_preferences>", buf, sizeof(buf)
            );
            if (retval) return "error copying global prefs";
            safe_strcat(global_prefs_xml, buf);
            safe_strcat(global_prefs_xml, "</global_preferences>\n");
            continue;
        }
        if (xp.match_tag("working_global_preferences")) {
            retval = xp.element_contents(
                "</working_global_preferences>",
                working_global_prefs_xml,
                sizeof(working_global_prefs_xml)
            );
            if (retval) return "error copying working global prefs";
            continue;
        }
        if (xp.parse_str("global_prefs_source_email_hash", global_prefs_source_email_hash, sizeof(global_prefs_source_email_hash))) continue;
        if (xp.match_tag("host_info")) {
            host.parse(xp);
            continue;
        }
        if (xp.match_tag("time_stats")) {
            host.parse_time_stats(xp);
            continue;
        }
        if (xp.match_tag("time_stats_log")) {
            handle_time_stats_log(xp.f->f);
            have_time_stats_log = true;
            continue;
        }
        if (xp.match_tag("net_stats")) {
            host.parse_net_stats(xp);
            continue;
        }
        if (xp.match_tag("disk_usage")) {
            host.parse_disk_usage(xp);
            continue;
        }
        if (xp.match_tag("result")) {
            retval = result.parse_from_client(xp);
            if (retval) continue;
            if (strstr(result.name, "download") || strstr(result.name, "upload")) {
                file_xfer_results.push_back(result);
                continue;
            }
#if 0   // enable if you need to limit CGI memory size
            if (results.size() >= 1024) {
                continue;
            }
#endif
            // check if client is sending the same result twice.
            // Shouldn't happen, but if it does bad things will happen
            //
            bool found = false;
            for (unsigned int i=0; i<results.size(); i++) {
                if (!strcmp(results[i].name, result.name)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                results.push_back(result);
            }
            continue;
        }
        if (xp.match_tag("code_sign_key")) {
            copy_element_contents(xp.f->f, "</code_sign_key>", code_sign_key, sizeof(code_sign_key));
            strip_whitespace(code_sign_key);
            continue;
        }
        if (xp.match_tag("msg_from_host")) {
            MSG_FROM_HOST_DESC md;
            retval = md.parse(xp);
            if (!retval) {
                msgs_from_host.push_back(md);
            }
            continue;
        }
        if (xp.match_tag("file_info")) {
            FILE_INFO fi;
            retval = fi.parse(xp);
            if (!retval) {
                file_infos.push_back(fi);
            }
            continue;
        }
        if (xp.match_tag("host_venue")) {
            continue;
        }
        if (xp.match_tag("other_results")) {
            have_other_results_list = true;
            while (!xp.get_tag()) {
                if (xp.match_tag("/other_results")) break;
                if (xp.match_tag("other_result")) {
                    OTHER_RESULT o_r;
                    retval = o_r.parse(xp);
                    if (!retval) {
                        other_results.push_back(o_r);
                    }
                }
            }
            continue;
        }
        if (xp.match_tag("in_progress_results")) {
            have_ip_results_list = true;
            int i = 0;
            double now = time(0);
            while (!xp.get_tag()) {
                if (xp.match_tag("/in_progress_results")) break;
                if (xp.match_tag("ip_result")) {
                    IP_RESULT ir;
                    retval = ir.parse(xp);
                    if (!retval) {
                        if (!strlen(ir.name)) {
                            sprintf(ir.name, "ip%d", i++);
                        }
                        ir.report_deadline -= now;
                        ip_results.push_back(ir);
                    }
                }
            }
            continue;
        }
        if (xp.match_tag("coprocs")) {
            coprocs.parse(xp);
            continue;
        }
        if (xp.parse_bool("client_cap_plan_class", client_cap_plan_class)) continue;
        if (xp.parse_int("sandbox", sandbox)) continue;
        if (xp.parse_int("allow_multiple_clients", allow_multiple_clients)) continue;
        if (xp.parse_string("client_opaque", client_opaque)) continue;

        if (xp.match_tag("active_task_set")) continue;
        if (xp.match_tag("app")) continue;
        if (xp.match_tag("app_version")) continue;
        if (xp.match_tag("duration_variability")) continue;
        if (xp.match_tag("new_version_check_time")) continue;
        if (xp.match_tag("newer_version")) continue;
        if (xp.match_tag("project")) continue;
        if (xp.match_tag("project_files")) continue;
        if (xp.match_tag("proxy_info")) continue;
        if (xp.match_tag("user_network_request")) continue;
        if (xp.match_tag("user_run_request")) continue;
        if (xp.match_tag("master_url")) continue;
        if (xp.match_tag("project_name")) continue;
        if (xp.match_tag("user_name")) continue;
        if (xp.match_tag("team_name")) continue;
        if (xp.match_tag("email_hash")) continue;
        if (xp.match_tag("user_total_credit")) continue;
        if (xp.match_tag("user_expavg_credit")) continue;
        if (xp.match_tag("user_create_time")) continue;
        if (xp.match_tag("host_total_credit")) continue;
        if (xp.match_tag("host_expavg_credit")) continue;
        if (xp.match_tag("host_create_time")) continue;
        if (xp.match_tag("nrpc_failures")) continue;
        if (xp.match_tag("master_fetch_failures")) continue;
        if (xp.match_tag("min_rpc_time")) continue;
        if (xp.match_tag("short_term_debt")) continue;
        if (xp.match_tag("long_term_debt")) continue;
        if (xp.match_tag("resource_share")) continue;
        if (xp.match_tag("scheduler_url")) continue;
        if (xp.match_tag("/project")) continue;
        if (xp.match_tag("?xml")) continue;

        log_messages.printf(MSG_NORMAL,
            "SCHEDULER_REQUEST::parse(): unexpected: %s\n", xp.parsed_tag
        );
        xp.skip_unexpected();
    }
    return "no end tag";
}
Beispiel #2
0
// return an error message or NULL
//
const char* SCHEDULER_REQUEST::parse(FILE* fin) {
    char buf[256];
    RESULT result;
    int retval;

    strcpy(authenticator, "");
    strcpy(platform.name, "");
    strcpy(cross_project_id, "");
    hostid = 0;
    core_client_major_version = 0;
    core_client_minor_version = 0;
    core_client_release = 0;
    rpc_seqno = 0;
    work_req_seconds = 0;
    cpu_req_secs = 0;
    cpu_req_instances = 0;
    resource_share_fraction = 1.0;
    rrs_fraction = 1.0;
    prrs_fraction = 1.0;
    cpu_estimated_delay = 0;
    strcpy(global_prefs_xml, "");
    strcpy(working_global_prefs_xml, "");
    strcpy(code_sign_key, "");
    memset(&global_prefs, 0, sizeof(global_prefs));
    memset(&host, 0, sizeof(host));
    have_other_results_list = false;
    have_ip_results_list = false;
    have_time_stats_log = false;
    client_cap_plan_class = false;
    sandbox = -1;
    coproc_cuda = 0;
    coproc_ati = 0;

    fgets(buf, sizeof(buf), fin);
    if (!match_tag(buf, "<scheduler_request>")) return "no start tag";
    while (fgets(buf, sizeof(buf), fin)) {
        // 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)) {
                if (strchr(buf, '\n')) break;
            }
            continue;
        }

        if (match_tag(buf, "</scheduler_request>")) {
            core_client_version = 10000*core_client_major_version + 100*core_client_minor_version + core_client_release;
            return NULL;
        }
        if (parse_str(buf, "<authenticator>", authenticator, sizeof(authenticator))) {
            remove_quotes(authenticator);
            continue;
        }
        if (parse_str(buf, "<cross_project_id>", cross_project_id, sizeof(cross_project_id))) continue;
        if (parse_int(buf, "<hostid>", hostid)) continue;
        if (parse_int(buf, "<rpc_seqno>", rpc_seqno)) continue;
        if (parse_str(buf, "<platform_name>", platform.name, sizeof(platform.name))) continue;
        if (match_tag(buf, "<alt_platform>")) {
            CLIENT_PLATFORM cp;
            retval = cp.parse(fin);
            if (!retval) {
                alt_platforms.push_back(cp);
            }
            continue;
        }
        if (match_tag(buf, "<app_versions>")) {
            while (fgets(buf, sizeof(buf), fin)) {
                if (match_tag(buf, "</app_versions>")) break;
                if (match_tag(buf, "<app_version>")) {
                    CLIENT_APP_VERSION cav;
                    retval = cav.parse(fin);
                    if (retval) {
                        g_reply->insert_message(
                            "Invalid app version description", "high"
                        );
                    } else {
                        client_app_versions.push_back(cav);
                    }
                }
            }
            continue;
        }
        if (parse_int(buf, "<core_client_major_version>", core_client_major_version)) continue;
        if (parse_int(buf, "<core_client_minor_version>", core_client_minor_version)) continue;
        if (parse_int(buf, "<core_client_release>", core_client_release)) continue;
        if (parse_double(buf, "<work_req_seconds>", work_req_seconds)) continue;
        if (parse_double(buf, "<cpu_req_secs>", cpu_req_secs)) continue;
        if (parse_double(buf, "<cpu_req_instances>", cpu_req_instances)) continue;
        if (parse_double(buf, "<resource_share_fraction>", resource_share_fraction)) continue;
        if (parse_double(buf, "<rrs_fraction>", rrs_fraction)) continue;
        if (parse_double(buf, "<prrs_fraction>", prrs_fraction)) continue;
        if (parse_double(buf, "<estimated_delay>", cpu_estimated_delay)) continue;
        if (parse_double(buf, "<duration_correction_factor>", host.duration_correction_factor)) continue;
        if (match_tag(buf, "<global_preferences>")) {
            strcpy(global_prefs_xml, "<global_preferences>\n");
            while (fgets(buf, sizeof(buf), fin)) {
                if (strstr(buf, "</global_preferences>")) break;
                safe_strcat(global_prefs_xml, buf);
            }
            safe_strcat(global_prefs_xml, "</global_preferences>\n");
            continue;
        }
        if (match_tag(buf, "<working_global_preferences>")) {
            while (fgets(buf, sizeof(buf), fin)) {
                if (strstr(buf, "</working_global_preferences>")) break;
                safe_strcat(working_global_prefs_xml, buf);
            }
            continue;
        }
        if (parse_str(buf, "<global_prefs_source_email_hash>", global_prefs_source_email_hash, sizeof(global_prefs_source_email_hash))) continue;
        if (match_tag(buf, "<host_info>")) {
            host.parse(fin);
            continue;
        }
        if (match_tag(buf, "<time_stats>")) {
            host.parse_time_stats(fin);
            continue;
        }
        if (match_tag(buf, "<time_stats_log>")) {
            handle_time_stats_log(fin);
            have_time_stats_log = true;
            continue;
        }
        if (match_tag(buf, "<net_stats>")) {
            host.parse_net_stats(fin);
            continue;
        }
        if (match_tag(buf, "<disk_usage>")) {
            host.parse_disk_usage(fin);
            continue;
        }
        if (match_tag(buf, "<result>")) {
            result.parse_from_client(fin);
            static int max_results = 200;
            --max_results;
            if (max_results >= 0)
            results.push_back(result);
            continue;
        }
        if (match_tag(buf, "<code_sign_key>")) {
            copy_element_contents(fin, "</code_sign_key>", code_sign_key, sizeof(code_sign_key));
            continue;
        }
        if (match_tag(buf, "<msg_from_host>")) {
            MSG_FROM_HOST_DESC md;
            retval = md.parse(fin);
            if (!retval) {
                msgs_from_host.push_back(md);
            }
            continue;
        }
        if (match_tag(buf, "<file_info>")) {
            FILE_INFO fi;
            retval = fi.parse(fin);
            if (!retval) {
                file_infos.push_back(fi);
            }
            continue;
        }
        if (match_tag(buf, "<host_venue>")) {
            continue;
        }
        if (match_tag(buf, "<other_results>")) {
            have_other_results_list = true;
            while (fgets(buf, sizeof(buf), fin)) {
                if (match_tag(buf, "</other_results>")) break;
                if (match_tag(buf, "<other_result>")) {
                    OTHER_RESULT o_r;
                    retval = o_r.parse(fin);
                    if (!retval) {
                        other_results.push_back(o_r);
                    }
                }
            }
            continue;
        }
        if (match_tag(buf, "<in_progress_results>")) {
            have_ip_results_list = true;
            int i = 0;
            double now = time(0);
            while (fgets(buf, sizeof(buf), fin)) {
                if (match_tag(buf, "</in_progress_results>")) break;
                if (match_tag(buf, "<ip_result>")) {
                    IP_RESULT ir;
                    retval = ir.parse(fin);
                    if (!retval) {
                        if (!strlen(ir.name)) {
                            sprintf(ir.name, "ip%d", i++);
                        }
                        ir.report_deadline -= now;
                        ip_results.push_back(ir);
                    }
                }
            }
            continue;
        }
        if (match_tag(buf, "coprocs")) {
            MIOFILE mf;
            mf.init_file(fin);
            coprocs.parse(mf);
            coproc_cuda = (COPROC_CUDA*)coprocs.lookup("CUDA");
            coproc_ati = (COPROC_ATI*)coprocs.lookup("ATI");
            continue;
        }
        if (parse_bool(buf, "client_cap_plan_class", client_cap_plan_class)) continue;
        if (parse_int(buf, "<sandbox>", sandbox)) continue;

        if (match_tag(buf, "<active_task_set>")) continue;
        if (match_tag(buf, "<app>")) continue;
        if (match_tag(buf, "<app_version>")) continue;
        if (match_tag(buf, "<duration_variability>")) continue;
        if (match_tag(buf, "<new_version_check_time>")) continue;
        if (match_tag(buf, "<newer_version>")) continue;
        if (match_tag(buf, "<project>")) continue;
        if (match_tag(buf, "<project_files>")) continue;
        if (match_tag(buf, "<proxy_info>")) continue;
        if (match_tag(buf, "<user_network_request>")) continue;
        if (match_tag(buf, "<user_run_request>")) continue;
        if (match_tag(buf, "<master_url>")) continue;
        if (match_tag(buf, "<project_name>")) continue;
        if (match_tag(buf, "<user_name>")) continue;
        if (match_tag(buf, "<team_name>")) continue;
        if (match_tag(buf, "<email_hash>")) continue;
        if (match_tag(buf, "<user_total_credit>")) continue;
        if (match_tag(buf, "<user_expavg_credit>")) continue;
        if (match_tag(buf, "<user_create_time>")) continue;
        if (match_tag(buf, "<host_total_credit>")) continue;
        if (match_tag(buf, "<host_expavg_credit>")) continue;
        if (match_tag(buf, "<host_create_time>")) continue;
        if (match_tag(buf, "<nrpc_failures>")) continue;
        if (match_tag(buf, "<master_fetch_failures>")) continue;
        if (match_tag(buf, "<min_rpc_time>")) continue;
        if (match_tag(buf, "<short_term_debt>")) continue;
        if (match_tag(buf, "<long_term_debt>")) continue;
        if (match_tag(buf, "<resource_share>")) continue;
        if (match_tag(buf, "<scheduler_url>")) continue;
        if (match_tag(buf, "</project>")) continue;
        if (match_tag(buf, "<?xml")) continue;
        strip_whitespace(buf);
        if (!strlen(buf)) continue;

        log_messages.printf(MSG_NORMAL,
            "SCHEDULER_REQUEST::parse(): unrecognized: %s\n", buf
        );
        MIOFILE mf;
        mf.init_file(fin);
        retval = skip_unrecognized(buf, mf);
        if (retval) return "unterminated unrecognized XML";
    }
    return "no end tag";
}