static void handle_acct_mgr_rpc(char* buf, MIOFILE& fout) { std::string url, name, password; std::string password_hash, name_lc; bool use_config_file = false; bool bad_arg = false; if (!parse_bool(buf, "use_config_file", use_config_file)) { if (!parse_str(buf, "<url>", url)) bad_arg = true; if (!parse_str(buf, "<name>", name)) bad_arg = true; if (!parse_str(buf, "<password>", password)) bad_arg = true; if (!bad_arg) { name_lc = name; downcase_string(name_lc); if (!starts_with(password, "hash:")) { password_hash = md5_string(password+name_lc); } else { // Remove 'hash:' password_hash = password.substr(5); } } } else { if (!strlen(gstate.acct_mgr_info.master_url)) { bad_arg = true; msg_printf(NULL, MSG_INTERNAL_ERROR, "Account manager info missing from config file" ); } else { url = gstate.acct_mgr_info.master_url; name = gstate.acct_mgr_info.login_name; password_hash = gstate.acct_mgr_info.password_hash; } } if (bad_arg) { fout.printf("<error>bad arg</error>\n"); } else { gstate.acct_mgr_op.do_rpc(url, name, password_hash, true); fout.printf("<success/>\n"); } }
// set remote desktop information if needed // void set_remote_desktop_info(APP_INIT_DATA& /* aid */, VBOX_VM& vm) { char buf[256]; if (vm.rd_host_port) { // Write info to disk // MIOFILE mf; FILE* f = boinc_fopen(REMOTEDESKTOP_FILENAME, "w"); mf.init_file(f); mf.printf( "<remote_desktop>\n" " <host_port>%d</host_port>\n" "</remote_desktop>\n", vm.rd_host_port ); fclose(f); sprintf(buf, "localhost:%d", vm.rd_host_port); boinc_remote_desktop_addr(buf); } }
void send_log_after(const char* filename, double t, MIOFILE& mf) { char buf[256]; double x; FILE* f = fopen(filename, "r"); if (!f) return; while (fgets(buf, 256, f)) { int n = sscanf(buf, "%lf", &x); if (n != 1) continue; if (x < t) continue; mf.printf("%s", buf); } fclose(f); }
int PROJECT_INIT::init() { clear(); FILE* f = fopen(PROJECT_INIT_FILENAME, "r"); if (!f) return 0; MIOFILE mf; mf.init_file(f); XML_PARSER xp(&mf); while (!xp.get_tag()) { if (xp.match_tag("/project_init")) break; else if (xp.parse_str("name", name, 256)) continue; else if (xp.parse_str("team_name", team_name, 256)) continue; else if (xp.parse_str("url", url, 256)) { canonicalize_master_url(url); continue; } else if (xp.parse_str("account_key", account_key, 256)) { continue; } } fclose(f); msg_printf(0, MSG_INFO, "Found project_init.xml for %s", url); return 0; }
int COPROC_REQ::parse(MIOFILE& fin) { char buf[1024]; strcpy(type, ""); count = 0; while (fin.fgets(buf, sizeof(buf))) { if (match_tag(buf, "</coproc>")) { if (!strlen(type)) return ERR_XML_PARSE; return 0; } if (parse_str(buf, "<type>", type, sizeof(type))) continue; if (parse_double(buf, "<count>", count)) continue; } return ERR_XML_PARSE; }
void COPROCS::write_xml(MIOFILE& mf, bool scheduler_rpc) { #ifndef _USING_FCGI_ mf.printf(" <coprocs>\n"); for (int i=1; i<n_rsc; i++) { switch (coproc_type_name_to_num(coprocs[i].type)) { case PROC_TYPE_NVIDIA_GPU: nvidia.write_xml(mf, scheduler_rpc); break; case PROC_TYPE_AMD_GPU: ati.write_xml(mf, scheduler_rpc); break; case PROC_TYPE_INTEL_GPU: intel_gpu.write_xml(mf, scheduler_rpc); break; default: coprocs[i].write_xml(mf, scheduler_rpc); } } mf.printf(" </coprocs>\n"); #endif }
static void handle_update_projects_apps(char* buf, bool is_local, MIOFILE& fout) { if (!is_local) { fout.printf("<failed/>\n"); return; } string url; if (!parse_str(buf, "<project_url>", url)) { fout.printf("<error>Missing URL</error>\n"); return; } for (unsigned int i=0;i<gstate.projects.size();i++) { PROJECT* project = gstate.projects[i]; if (!strcmp(project->master_url,url.c_str())) { if (log_flags.update_apps_debug) msg_printf(project, MSG_INFO, "init process"); gstate.init_update_project_apps(project); fout.printf("<success/>"); } } fout.printf("<error>Project not attached</error>\n"); }
static void handle_acct_mgr_info(char*, MIOFILE& fout) { fout.printf( "<acct_mgr_info>\n" " <acct_mgr_url>%s</acct_mgr_url>\n" " <acct_mgr_name>%s</acct_mgr_name>\n", gstate.acct_mgr_info.master_url, gstate.acct_mgr_info.project_name ); if (strlen(gstate.acct_mgr_info.login_name)) { fout.printf(" <have_credentials/>\n"); } if (gstate.acct_mgr_info.cookie_required) { fout.printf(" <cookie_required/>\n"); fout.printf( " <cookie_failure_url>%s</cookie_failure_url>\n", gstate.acct_mgr_info.cookie_failure_url ); } fout.printf("</acct_mgr_info>\n"); }
int COPROCS::write_coproc_info_file(vector<string> &warnings) { MIOFILE mf; unsigned int i, temp; FILE* f; f = boinc_fopen(COPROC_INFO_FILENAME, "wb"); if (!f) return ERR_FOPEN; mf.init_file(f); mf.printf(" <coprocs>\n"); if (nvidia.have_cuda) { mf.printf(" <have_cuda>1</have_cuda>\n"); mf.printf(" <cuda_version>%d</cuda_version>\n", nvidia.cuda_version); } for (i=0; i<ati_gpus.size(); ++i) { ati_gpus[i].write_xml(mf, false); } for (i=0; i<nvidia_gpus.size(); ++i) { temp = nvidia_gpus[i].count; nvidia_gpus[i].count = 1; nvidia_gpus[i].pci_infos[0] = nvidia_gpus[i].pci_info; nvidia_gpus[i].write_xml(mf, false); nvidia_gpus[i].count = temp; } for (i=0; i<intel_gpus.size(); ++i) { intel_gpus[i].write_xml(mf, false); } for (i=0; i<ati_opencls.size(); ++i) { ati_opencls[i].write_xml(mf, "ati_opencl", true); } for (i=0; i<nvidia_opencls.size(); ++i) { nvidia_opencls[i].write_xml(mf, "nvidia_opencl", true); } for (i=0; i<intel_gpu_opencls.size(); ++i) { intel_gpu_opencls[i].write_xml(mf, "intel_gpu_opencl", true); } for (i=0; i<other_opencls.size(); i++) { other_opencls[i].write_xml(mf, "other_opencl", true); } for (i=0; i<cpu_opencls.size(); i++) { cpu_opencls[i].write_xml(mf); } for (i=0; i<warnings.size(); ++i) { mf.printf("<warning>%s</warning>\n", warnings[i].c_str()); } mf.printf(" </coprocs>\n"); fclose(f); return 0; }
int parse_job_file() { MIOFILE mf; char tag[1024], buf[256], buf2[256]; bool is_tag; boinc_resolve_filename(JOB_FILENAME, buf, 1024); FILE* f = boinc_fopen(buf, "r"); if (!f) { fprintf(stderr, "%s can't open job file %s\n", boinc_msg_prefix(buf2, sizeof(buf2)), buf ); return ERR_FOPEN; } mf.init_file(f); XML_PARSER xp(&mf); if (!xp.parse_start("job_desc")) return ERR_XML_PARSE; while (!xp.get(tag, sizeof(tag), is_tag)) { if (!is_tag) { fprintf(stderr, "%s SCHED_CONFIG::parse(): unexpected text %s\n", boinc_msg_prefix(buf2, sizeof(buf2)), tag ); continue; } if (!strcmp(tag, "/job_desc")) { fclose(f); return 0; } if (!strcmp(tag, "vm")) { vm.parse(xp); } } fclose(f); return ERR_XML_PARSE; }
void parse(FILE* f) { char tag[256]; bool is_tag, flag; MIOFILE mf; XML_PARSER xp(&mf); char name[256]; int val; double x; mf.init_file(f); if (!xp.parse_start("blah")) { printf("missing start tag\n"); return; } while (!xp.get(tag, sizeof(tag), is_tag)) { if (!is_tag) { printf("unexpected text: %s\n", tag); continue; } if (!strcmp(tag, "/blah")) { printf("success\n"); return; } else if (xp.parse_str(tag, "str", name, sizeof(name))) { printf("got str: %s\n", name); } else if (xp.parse_int(tag, "int", val)) { printf("got int: %d\n", val); } else if (xp.parse_double(tag, "double", x)) { printf("got double: %f\n", x); } else if (xp.parse_bool(tag, "bool", flag)) { printf("got bool: %d\n", flag); } else { printf("unparsed tag: %s\n", tag); xp.skip_unexpected(tag, true, "xml test"); } } printf("unexpected EOF\n"); }
// <active_task_state> is here for the benefit of 3rd-party software // that reads the client state file // int ACTIVE_TASK::write(MIOFILE& fout) { fout.printf( "<active_task>\n" " <project_master_url>%s</project_master_url>\n" " <result_name>%s</result_name>\n" " <active_task_state>%d</active_task_state>\n" " <app_version_num>%d</app_version_num>\n" " <slot>%d</slot>\n" " <checkpoint_cpu_time>%f</checkpoint_cpu_time>\n" " <checkpoint_elapsed_time>%f</checkpoint_elapsed_time>\n" " <checkpoint_fraction_done>%f</checkpoint_fraction_done>\n" " <checkpoint_fraction_done_elapsed_time>%f</checkpoint_fraction_done_elapsed_time>\n" " <current_cpu_time>%f</current_cpu_time>\n" " <once_ran_edf>%d</once_ran_edf>\n" " <swap_size>%f</swap_size>\n" " <working_set_size>%f</working_set_size>\n" " <working_set_size_smoothed>%f</working_set_size_smoothed>\n" " <page_fault_rate>%f</page_fault_rate>\n", result->project->master_url, result->name, task_state(), app_version->version_num, slot, checkpoint_cpu_time, checkpoint_elapsed_time, checkpoint_fraction_done, checkpoint_fraction_done_elapsed_time, current_cpu_time, once_ran_edf?1:0, procinfo.swap_size, procinfo.working_set_size, procinfo.working_set_size_smoothed, procinfo.page_fault_rate ); fout.printf("</active_task>\n"); return 0; }
int WORKUNIT::write(MIOFILE& out) { unsigned int i; out.printf( "<workunit>\n" " <name>%s</name>\n" " <app_name>%s</app_name>\n" " <version_num>%d</version_num>\n" //" <env_vars>%s</env_vars>\n" " <rsc_fpops_est>%f</rsc_fpops_est>\n" " <rsc_fpops_bound>%f</rsc_fpops_bound>\n" " <rsc_memory_bound>%f</rsc_memory_bound>\n" " <rsc_disk_bound>%f</rsc_disk_bound>\n", name, app_name, version_num, //env_vars, rsc_fpops_est, rsc_fpops_bound, rsc_memory_bound, rsc_disk_bound ); if (command_line.size()) { out.printf( " <command_line>\n" "%s\n" " </command_line>\n", command_line.c_str() ); } for (i=0; i<input_files.size(); i++) { input_files[i].write(out); } out.printf("</workunit>\n"); return 0; }
void RSS_FEED::write(MIOFILE& fout) { char buf[256]; safe_strcpy(buf, url); xml_escape(url, buf, sizeof(buf)); fout.printf( " <rss_feed>\n" " <url>%s</url>\n" " <poll_interval>%f</poll_interval>\n" " <next_poll_time>%f</next_poll_time>\n" " </rss_feed>\n", buf, poll_interval, next_poll_time ); }
bool CSkinManager::ReloadSkin(wxString strSkin) { int retval = ERR_XML_PARSE; FILE* p; MIOFILE mf; // This fixes a (rare) crash bug if (strSkin.IsEmpty()) { strSkin = GetDefaultSkinName(); } // Clear out all the old stuff Clear(); // Set the default skin back to Default m_strSelectedSkin = strSkin; // TODO: Eliminate the <en> tags: localization is no longer in skin files. p = fopen((const char*)ConstructSkinFileName().mb_str(wxConvUTF8), "r"); if (p) { mf.init_file(p); retval = Parse(mf, wxT("en")); fclose(p); } if (retval && show_error_msgs) { fprintf(stderr, "Skin Manager: Failed to load skin '%s'.\n", (const char *)ConstructSkinFileName().mb_str(wxConvUTF8)); } InitializeDelayedValidation(); // Tell whichever UI elements that are loaded to reload the // skinable resources they use. wxGetApp().FireReloadSkin(); return true; }
// Write XML information about a persistent file transfer // int PERS_FILE_XFER::write(MIOFILE& fout) { fout.printf( " <persistent_file_xfer>\n" " <num_retries>%d</num_retries>\n" " <first_request_time>%f</first_request_time>\n" " <next_request_time>%f</next_request_time>\n" " <time_so_far>%f</time_so_far>\n" " <last_bytes_xferred>%f</last_bytes_xferred>\n" " <is_upload>%d</is_upload>\n" " </persistent_file_xfer>\n", nretry, first_request_time, next_request_time, time_so_far, last_bytes_xferred, is_upload?1:0 ); // the following is for GUI RPCs // if (fxp) { fout.printf( " <file_xfer>\n" " <bytes_xferred>%f</bytes_xferred>\n" " <file_offset>%f</file_offset>\n" " <xfer_speed>%f</xfer_speed>\n" " <url>%s</url>\n" " </file_xfer>\n", fxp->bytes_xferred, fxp->file_offset, fxp->xfer_speed, fxp->m_url ); } return 0; }
void EXCLUDE_GPU::write(MIOFILE& out) { out.printf( " <exclude_gpu>\n" " <url>%s</url>\n" " <device_num>%d</device_num>\n", url.c_str(), device_num ); if (type.length()) { out.printf( " <type>%s</type>\n", type.c_str() ); } if (appname.length()) { out.printf( " <app>%s</app>\n", appname.c_str() ); } out.printf( " </exclude_gpu>\n" ); }
int ACCT_MGR_INFO::parse_login_file(FILE* p) { char tag[1024]; bool is_tag; MIOFILE mf; int retval; mf.init_file(p); XML_PARSER xp(&mf); if (!xp.parse_start("acct_mgr_login")) { // } while (!xp.get(tag, sizeof(tag), is_tag)) { if (!is_tag) { printf("unexpected text: %s\n", 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")) { retval = xp.element_contents("</opaque>", opaque, sizeof(opaque)); continue; } if (log_flags.unparsed_xml) { msg_printf(NULL, MSG_INFO, "[unparsed_xml] ACCT_MGR_INFO::parse_login: unrecognized %s", tag ); } xp.skip_unexpected( tag, log_flags.unparsed_xml, "ACCT_MGR_INFO::parse_login_file" ); } return 0; }
static void handle_set_network_mode(char* buf, MIOFILE& fout) { double duration = 0; int mode; parse_double(buf, "<duration>", duration); if (match_tag(buf, "<always")) { mode = RUN_MODE_ALWAYS; } else if (match_tag(buf, "<never")) { mode = RUN_MODE_NEVER; } else if (match_tag(buf, "<auto")) { mode = RUN_MODE_AUTO; } else if (match_tag(buf, "<restore")) { mode = RUN_MODE_RESTORE; } else { fout.printf("<error>Missing mode</error>\n"); return; } // user is turning network on/off explicitly, // so disable the "5 minute grace period" mechanism // gstate.gui_rpcs.time_of_last_rpc_needing_network = 0; gstate.network_mode.set(mode, duration); fout.printf("<success/>\n"); }
/// Copy from a file to static buffer. int copy_element_contents(MIOFILE& in, const char* end_tag, char* p, int len) { char buf[256]; int n; strcpy(p, ""); while (in.fgets(buf, 256)) { if (strstr(buf, end_tag)) { return 0; } n = (int)strlen(buf); if (n >= len-1) return ERR_XML_PARSE; strcat(p, buf); len -= n; } return ERR_XML_PARSE; }
int GUI_RPC_CONN::handle_auth2(char* buf, MIOFILE& fout) { char nonce_hash[256], nonce_hash_correct[256], buf2[256]; if (!parse_str(buf, "<nonce_hash>", nonce_hash, 256)) { auth_failure(fout); return ERR_AUTHENTICATOR; } sprintf(buf2, "%s%s", nonce, gstate.gui_rpcs.password); md5_block((const unsigned char*)buf2, (int)strlen(buf2), nonce_hash_correct); if (strcmp(nonce_hash, nonce_hash_correct)) { auth_failure(fout); return ERR_AUTHENTICATOR; } fout.printf("<authorized/>\n"); auth_needed = false; return 0; }
int CSkinWizardATP::Parse(MIOFILE& in) { char buf[256]; std::string strBuffer; while (in.fgets(buf, 256)) { if (match_tag(buf, "</attach_to_project>")) break; else if (parse_str(buf, "<title>", strBuffer)) { m_strTitle = wxString(strBuffer.c_str(), wxConvUTF8); continue; } } InitializeDelayedValidation(); return 0; }
int CSkinWizardATAM::Parse(MIOFILE& in) { char buf[256]; std::string strBuffer; while (in.fgets(buf, 256)) { if (match_tag(buf, "</attach_to_account_manager>")) break; else if (parse_str(buf, "<account_info_message>", strBuffer)) { m_strAccountInfoMessage = wxString(strBuffer.c_str(), wxConvUTF8); continue; } } InitializeDelayedValidation(); return 0; }
int NET_STATS::parse(MIOFILE& in) { char buf[256]; up.clear(); down.clear(); while (in.fgets(buf, 256)) { if (match_tag(buf, "</net_stats>")) return 0; if (parse_double(buf, "<bwup>", up.max_rate)) continue; if (parse_double(buf, "<avg_up>", up.avg_rate)) continue; if (parse_double(buf, "<avg_time_up>", up.avg_time)) continue; if (parse_double(buf, "<bwdown>", down.max_rate)) continue; if (parse_double(buf, "<avg_down>", down.avg_rate)) continue; if (parse_double(buf, "<avg_time_down>", down.avg_time)) continue; handle_unparsed_xml_warning("NET_STATS::parse", buf); } return ERR_XML_PARSE; }
int MOZILLA_PROFILE::parse(MIOFILE& in) { char buf[512]; std::string sn; std::string sv; while (in.fgets(buf, 512)) { if (starts_with(buf, "\n")) return 0; if (starts_with(buf, "\r\n")) return 0; if (!parse_name_value_pair(buf, sn, sv)) continue; if ("Name" == sn) name = sv; if ("Path" == sn) path = sv; if (("IsRelative" == sn) && ("1" == sv)) is_relative = true; if (("Default" == sn) && ("1" == sv)) is_default = true; } return ERR_FREAD; }
int MOZILLA_PROFILES::parse(MIOFILE& in) { char buf[512]; MOZILLA_PROFILE* p = NULL; while (in.fgets(buf, 512)) { if (starts_with(buf, "[Profile")) { p = new MOZILLA_PROFILE; if (!p->parse( in )) { profiles.push_back( p ); } else { delete p; } } } return 0; }
int CSkinWizards::Parse(MIOFILE& in) { char buf[256]; while (in.fgets(buf, 256)) { if (match_tag(buf, "</wizards>")) break; else if (match_tag(buf, "<attach_to_project>")) { m_AttachToProjectWizard.Parse(in); continue; } else if (match_tag(buf, "<attach_to_account_manager>")) { m_AttachToAccountManagerWizard.Parse(in); continue; } } InitializeDelayedValidation(); return 0; }
int HOST_INFO::parse(MIOFILE& in, bool benchmarks_only) { char buf[1024]; while (in.fgets(buf, sizeof(buf))) { if (match_tag(buf, "</host_info>")) return 0; else if (parse_double(buf, "<p_fpops>", p_fpops)) { // fix foolishness that could result in negative value here // if (p_fpops < 0) p_fpops = -p_fpops; continue; } else if (parse_double(buf, "<p_iops>", p_iops)) { if (p_iops < 0) p_iops = -p_iops; continue; } else if (parse_double(buf, "<p_membw>", p_membw)) { if (p_membw < 0) p_membw = -p_membw; continue; } else if (parse_double(buf, "<p_calculated>", p_calculated)) continue; if (benchmarks_only) continue; if (parse_int(buf, "<timezone>", timezone)) continue; else if (parse_str(buf, "<domain_name>", domain_name, sizeof(domain_name))) continue; else if (parse_str(buf, "<ip_addr>", ip_addr, sizeof(ip_addr))) continue; else if (parse_str(buf, "<host_cpid>", host_cpid, sizeof(host_cpid))) continue; else if (parse_int(buf, "<p_ncpus>", p_ncpus)) continue; else if (parse_str(buf, "<p_vendor>", p_vendor, sizeof(p_vendor))) continue; else if (parse_str(buf, "<p_model>", p_model, sizeof(p_model))) continue; else if (parse_str(buf, "<p_features>", p_features, sizeof(p_features))) continue; else if (parse_double(buf, "<m_nbytes>", m_nbytes)) continue; else if (parse_double(buf, "<m_cache>", m_cache)) continue; else if (parse_double(buf, "<m_swap>", m_swap)) continue; else if (parse_double(buf, "<d_total>", d_total)) continue; else if (parse_double(buf, "<d_free>", d_free)) continue; else if (parse_str(buf, "<os_name>", os_name, sizeof(os_name))) continue; else if (parse_str(buf, "<os_version>", os_version, sizeof(os_version))) continue; else if (match_tag(buf, "<coprocs>")) { coprocs.parse(in); } } return ERR_XML_PARSE; }
int NET_STATS::write(MIOFILE& out) { out.printf( "<net_stats>\n" " <bwup>%f</bwup>\n" " <avg_up>%f</avg_up>\n" " <avg_time_up>%f</avg_time_up>\n" " <bwdown>%f</bwdown>\n" " <avg_down>%f</avg_down>\n" " <avg_time_down>%f</avg_time_down>\n" "</net_stats>\n", up.max_rate, up.avg_rate, up.avg_time, down.max_rate, down.avg_rate, down.avg_time ); return 0; }
int CSkinSimple::Parse(MIOFILE& in) { char buf[256]; std::string strBuffer; while (in.fgets(buf, 256)) { if (match_tag(buf, "</simple>")) break; else if (match_tag(buf, "<background_image>")) { m_BackgroundImage.Parse(in); continue; } else if (match_tag(buf, "<dialog_background_image>")) { m_DialogBackgroundImage.Parse(in); continue; } else if (match_tag(buf, "<project_image>")) { m_ProjectImage.Parse(in); continue; } else if (parse_str(buf, "<static_line_color>", strBuffer)) { m_StaticLineColor = ParseColor(wxString(strBuffer.c_str(), wxConvUTF8)); continue; } else if (parse_str(buf, "<notice_alert_color>", strBuffer)) { m_NoticeAlertColor = ParseColor(wxString(strBuffer.c_str(), wxConvUTF8)); continue; } else if (match_tag(buf, "<workunit_animation_image>")) { m_WorkunitAnimationImage.Parse(in); continue; } else if (match_tag(buf, "<workunit_running_image>")) { m_WorkunitRunningImage.Parse(in); continue; } else if (match_tag(buf, "<workunit_suspended_image>")) { m_WorkunitSuspendedImage.Parse(in); continue; } else if (match_tag(buf, "<workunit_waiting_image>")) { m_WorkunitWaitingImage.Parse(in); continue; } else if (parse_int(buf, "<panel_opacity>", m_iPanelOpacity)) { continue; } } InitializeDelayedValidation(); return 0; }