// The contents of this file are subject to the Mozilla Public License // Version 1.0 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License at // http://www.mozilla.org/MPL/ // // Software distributed under the License is distributed on an "AS IS" // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the // License for the specific language governing rights and limitations // under the License. // // The Original Code is the Berkeley Open Infrastructure for Network Computing. // // The Initial Developer of the Original Code is the SETI@home project. // Portions created by the SETI@home project are Copyright (C) 2002 // University of California at Berkeley. All Rights Reserved. // // Contributor(s): // #include #include #include "parse.h" #include "server_types.h" SCHEDULER_REQUEST::SCHEDULER_REQUEST() { prefs_xml = 0; code_sign_key = 0; } SCHEDULER_REQUEST::~SCHEDULER_REQUEST() { if (prefs_xml) free(prefs_xml); if (code_sign_key) free(code_sign_key); } int SCHEDULER_REQUEST::parse(FILE* fin) { char buf[256]; RESULT result; assert(fin!=NULL); prefs_mod_time = 0; strcpy(authenticator, ""); hostid = 0; work_req_seconds = 0; prefs_mod_time = 0; prefs_xml = strdup(""); fgets(buf, 256, fin); if (!match_tag(buf, "")) return 1; while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_str(buf, "", authenticator)) continue; else if (parse_int(buf, "", hostid)) continue; else if (parse_int(buf, "", rpc_seqno)) continue; else if (parse_str(buf, "", platform_name)) continue; else if (parse_int(buf, "", core_client_version)) continue; else if (parse_int(buf, "", work_req_seconds)) continue; else if (parse_int(buf, "", (int)prefs_mod_time)) { continue; } else if (match_tag(buf, "")) { while (fgets(buf, 256, fin)) { if (strstr(buf, "")) break; strcatdup(prefs_xml, buf); } } else if (match_tag(buf, "")) { host.parse(fin); continue; } else if (match_tag(buf, "")) { host.parse_time_stats(fin); continue; } else if (match_tag(buf, "")) { host.parse_net_stats(fin); continue; } else if (match_tag(buf, "")) { result.parse_from_client(fin); results.push_back(result); continue; } else if (match_tag(buf, "")) { dup_element_contents(fin, "", &code_sign_key); } else fprintf(stderr, "SCHEDULER_REQUEST::parse(): unrecognized: %s\n", buf); } return 1; } SCHEDULER_REPLY::SCHEDULER_REPLY() { request_delay = 0; hostid = 0; strcpy(message, ""); strcpy(message_priority, ""); send_prefs = false; code_sign_key = 0; code_sign_key_signature = 0; } SCHEDULER_REPLY::~SCHEDULER_REPLY() { if (code_sign_key) free(code_sign_key); if (code_sign_key_signature) free(code_sign_key_signature); } int SCHEDULER_REPLY::write(FILE* fout) { unsigned int i, j; assert(fout!=NULL); fprintf(fout, "\n" ); if (request_delay) { fprintf(fout, "%d\n", request_delay); } if (strlen(message)) { fprintf(fout, "%s\n", message_priority, message ); } if (hostid) { fprintf(fout, "%d\n", hostid); } if (send_prefs) { fprintf(fout, "%d\n", user.prefs_mod_time ); fputs(user.prefs, fout); } // acknowledge results // for (i=0; i\n" " %s\n" "\n", result_acks[i].name ); } for (i=0; i\n", fout); fputs(code_sign_key, fout); fputs("\n", fout); } if (code_sign_key_signature) { fputs("\n", fout); fputs(code_sign_key_signature, fout); fputs("\n", fout); } fprintf(fout, "\n" ); return 0; } void SCHEDULER_REPLY::insert_app_unique(APP& app) { unsigned int i; for (i=0; i\n" " %s\n" " %d\n" "\n", name, prod_vers // TODO: handle other phases ); return 0; } int APP_VERSION::write(FILE* fout, APP& app) { fputs(xml_doc, fout); return 0; } int RESULT::parse_from_client(FILE* fin) { char buf[256]; assert(fin!=NULL); memset(this, 0, sizeof(RESULT)); while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_str(buf, "", name)) continue; else if (parse_int(buf, "", exit_status)) continue; else if (parse_double(buf, "", cpu_time)) continue; else if (match_tag(buf, "")) { strcat(xml_doc_out, buf); while (fgets(buf, 256, fin)) { // protect againt buffer overrun if (strlen(buf) + strlen(xml_doc_out) <= MAX_BLOB_SIZE) { strcat(xml_doc_out, buf); } if (match_tag(buf, "")) break; } continue; } else if (match_tag(buf, "" )) { while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) break; if (strlen(stderr_out) + strlen(buf) < MAX_BLOB_SIZE) { strcat(stderr_out, buf); } } continue; } else fprintf(stderr, "RESULT::parse_from_client(): unrecognized: %s\n", buf); } return 1; } int HOST::parse(FILE* fin) { char buf[256]; assert(fin!=NULL); while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_int(buf, "", timezone)) continue; else if (parse_str(buf, "", domain_name)) continue; else if (parse_str(buf, "", serialnum)) continue; else if (parse_str(buf, "", last_ip_addr)) continue; else if (parse_int(buf, "", p_ncpus)) continue; else if (parse_str(buf, "", p_vendor)) continue; else if (parse_str(buf, "", p_model)) continue; else if (parse_double(buf, "", p_fpops)) continue; else if (parse_double(buf, "", p_iops)) continue; else if (parse_double(buf, "", p_membw)) continue; else if (parse_double(buf, "", p_calculated)) continue; else if (parse_str(buf, "", os_name)) continue; else if (parse_str(buf, "", os_version)) continue; else if (parse_double(buf, "", m_nbytes)) continue; else if (parse_double(buf, "", m_cache)) continue; else if (parse_double(buf, "", m_swap)) continue; else if (parse_double(buf, "", d_total)) continue; else if (parse_double(buf, "", d_free)) continue; else if (parse_double(buf, "", n_bwup)) continue; else if (parse_double(buf, "", n_bwdown)) continue; else fprintf(stderr, "HOST::parse(): unrecognized: %s\n", buf); } return 1; } int HOST::parse_time_stats(FILE* fin) { char buf[256]; assert(fin!=NULL); while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_double(buf, "", on_frac)) continue; else if (parse_double(buf, "", connected_frac)) continue; else if (parse_double(buf, "", active_frac)) continue; else fprintf(stderr, "HOST::parse_time_stats(): unrecognized: %s\n", buf); } return 1; } int HOST::parse_net_stats(FILE* fin) { char buf[256]; while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_double(buf, "", n_bwup)) continue; else if (parse_double(buf, "", n_bwdown)) continue; else fprintf(stderr, "HOST::parse_net_stats(): unrecognized: %s\n", buf); } return 1; } #if 0 DB_CACHE::DB_CACHE() { } int DB_CACHE::read_db() { PLATFORM platform; APP app; APP_VERSION app_version; while (!db_platform_enum(platform)) { platforms.push_back(platform); } while (!db_app_enum(app)) { apps.push_back(app); } while (!db_app_version_enum(app_version)) { app_versions.push_back(app_version); } return 0; } PLATFORM* DB_CACHE::lookup_platform(char* name) { unsigned int i; assert(name!=NULL); for (i=0; i=0); for (i=0; iappid == appid && avp->platformid == platformid && avp->version_num == version) { return avp; } } return 0; } #endif