#include #include #include #include #include #include #include "parse.h" #include "error_numbers.h" #include "gui_rpc_client.h" int RPC_CLIENT::init(char* path) { int sock, retval; sockaddr_un addr; addr.sun_family = AF_UNIX; strcpy(addr.sun_path, path); sock = socket(AF_UNIX, SOCK_STREAM, 0); retval = connect(sock, (const sockaddr*)(&addr), sizeof(addr)); if (retval) { perror("connect"); exit(1); } fin = fdopen(dup(sock), "r"); fout = fdopen(sock, "w"); } RPC_CLIENT::~RPC_CLIENT() { fclose(fin); fclose(fout); } int RPC_CLIENT::get_projects(vector& projects) { char buf[256]; int retval; fprintf(fout, "\n"); fflush(fout); while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) continue; else if (match_tag(buf, "")) return 0; else if (match_tag(buf, "")) { PROJECT project; retval = project.parse_state(fin); if (!retval) { projects.push_back(project); } } else { fprintf(stderr, "unrecognized: %s", buf); } } return ERR_XML_PARSE; } int PROJECT::parse_state(FILE* in) { char buf[256]; STRING256 string; strcpy(project_name, ""); strcpy(user_name, ""); strcpy(team_name, ""); resource_share = 100; exp_avg_cpu = 0; exp_avg_mod_time = 0; min_rpc_time = 0; min_report_min_rpc_time = 0; nrpc_failures = 0; master_url_fetch_pending = false; sched_rpc_pending = false; scheduler_urls.clear(); while (fgets(buf, 256, in)) { if (match_tag(buf, "")) return 0; else if (parse_str(buf, "", string.text, sizeof(string.text))) { scheduler_urls.push_back(string); continue; } else if (parse_str(buf, "", master_url, sizeof(master_url))) continue; else if (parse_str(buf, "", project_name, sizeof(project_name))) continue; else if (parse_str(buf, "", user_name, sizeof(user_name))) continue; else if (parse_str(buf, "", team_name, sizeof(team_name))) continue; else if (parse_double(buf, "", user_total_credit)) continue; else if (parse_double(buf, "", user_expavg_credit)) continue; else if (parse_int(buf, "", (int &)user_create_time)) continue; else if (parse_int(buf, "", rpc_seqno)) continue; else if (parse_int(buf, "", hostid)) continue; else if (parse_double(buf, "", host_total_credit)) continue; else if (parse_double(buf, "", host_expavg_credit)) continue; else if (parse_int(buf, "", (int &)host_create_time)) continue; else if (parse_double(buf, "", exp_avg_cpu)) continue; else if (parse_int(buf, "", exp_avg_mod_time)) continue; else if (match_tag(buf, "")) { copy_element_contents( in, "", code_sign_key, sizeof(code_sign_key) ); } else if (parse_int(buf, "", nrpc_failures)) continue; else if (parse_int(buf, "", master_fetch_failures)) continue; else if (parse_int(buf, "", (int&)min_rpc_time)) continue; else if (match_tag(buf, "")) master_url_fetch_pending = true; else if (match_tag(buf, "")) sched_rpc_pending = true; else printf("PROJECT::parse_state(): unrecognized: %s\n", buf); } return ERR_XML_PARSE; } PROJECT::PROJECT() { init(); } void PROJECT::init() { strcpy(master_url, ""); strcpy(authenticator, ""); project_specific_prefs = ""; resource_share = 100; strcpy(project_name, ""); strcpy(user_name, ""); strcpy(team_name, ""); user_total_credit = 0; user_expavg_credit = 0; user_create_time = 0; rpc_seqno = 0; hostid = 0; host_total_credit = 0; host_expavg_credit = 0; host_create_time = 0; exp_avg_cpu = 0; exp_avg_mod_time = 0; strcpy(code_sign_key, ""); nrpc_failures = 0; min_rpc_time = 0; min_report_min_rpc_time = 0; master_fetch_failures = 0; resource_debt = 0; debt_order = 0; master_url_fetch_pending = false; sched_rpc_pending = false; tentative = false; } PROJECT::~PROJECT() { }