2002-04-30 22:22:54 +00:00
|
|
|
// 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):
|
|
|
|
//
|
|
|
|
|
2002-09-26 23:12:13 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <strings.h>
|
2002-07-11 01:09:53 +00:00
|
|
|
#include <assert.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "parse.h"
|
2003-04-03 18:35:40 +00:00
|
|
|
#include "util.h"
|
2002-08-25 07:54:33 +00:00
|
|
|
#include "main.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "server_types.h"
|
|
|
|
|
|
|
|
SCHEDULER_REQUEST::SCHEDULER_REQUEST() {
|
|
|
|
}
|
|
|
|
|
|
|
|
SCHEDULER_REQUEST::~SCHEDULER_REQUEST() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int SCHEDULER_REQUEST::parse(FILE* fin) {
|
2003-01-07 01:02:08 +00:00
|
|
|
char buf[256], ebuf[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
RESULT result;
|
2002-07-11 01:09:53 +00:00
|
|
|
assert(fin!=NULL);
|
2002-04-30 22:22:54 +00:00
|
|
|
strcpy(authenticator, "");
|
|
|
|
hostid = 0;
|
|
|
|
work_req_seconds = 0;
|
2003-04-03 18:35:40 +00:00
|
|
|
strcpy(global_prefs_xml, "");
|
|
|
|
strcpy(code_sign_key, "");
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
fgets(buf, 256, fin);
|
|
|
|
if (!match_tag(buf, "<scheduler_request>")) return 1;
|
|
|
|
while (fgets(buf, 256, fin)) {
|
|
|
|
if (match_tag(buf, "</scheduler_request>")) return 0;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<authenticator>", authenticator, sizeof(authenticator))) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_int(buf, "<hostid>", hostid)) continue;
|
|
|
|
else if (parse_int(buf, "<rpc_seqno>", rpc_seqno)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<platform_name>", platform_name, sizeof(platform_name))) continue;
|
2002-12-02 04:29:40 +00:00
|
|
|
else if (parse_int(buf, "<core_client_major_version>", core_client_major_version)) continue;
|
|
|
|
else if (parse_int(buf, "<core_client_minor_version>", core_client_minor_version)) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_int(buf, "<work_req_seconds>", work_req_seconds)) continue;
|
2002-09-29 00:32:11 +00:00
|
|
|
else if (match_tag(buf, "<global_preferences>")) {
|
2003-04-03 18:35:40 +00:00
|
|
|
strcpy(global_prefs_xml, "<global_preferences>\n");
|
2002-06-01 20:26:21 +00:00
|
|
|
while (fgets(buf, 256, fin)) {
|
2002-09-29 00:32:11 +00:00
|
|
|
if (strstr(buf, "</global_preferences>")) break;
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcat(global_prefs_xml, buf);
|
2002-06-01 20:26:21 +00:00
|
|
|
}
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcat(global_prefs_xml, "</global_preferences>\n");
|
2002-06-01 20:26:21 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (match_tag(buf, "<host_info>")) {
|
|
|
|
host.parse(fin);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(buf, "<time_stats>")) {
|
|
|
|
host.parse_time_stats(fin);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(buf, "<net_stats>")) {
|
|
|
|
host.parse_net_stats(fin);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (match_tag(buf, "<result>")) {
|
|
|
|
result.parse_from_client(fin);
|
|
|
|
results.push_back(result);
|
|
|
|
continue;
|
|
|
|
}
|
2002-07-07 20:39:24 +00:00
|
|
|
else if (match_tag(buf, "<code_sign_key>")) {
|
2003-04-03 18:35:40 +00:00
|
|
|
copy_element_contents(fin, "</code_sign_key>", code_sign_key, sizeof(code_sign_key));
|
2002-07-07 20:39:24 +00:00
|
|
|
}
|
2003-01-07 01:02:08 +00:00
|
|
|
else {
|
|
|
|
sprintf(ebuf, "SCHEDULER_REQUEST::parse(): unrecognized: %s\n", buf);
|
|
|
|
write_log(ebuf);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCHEDULER_REPLY::SCHEDULER_REPLY() {
|
|
|
|
request_delay = 0;
|
|
|
|
hostid = 0;
|
2002-05-17 22:33:57 +00:00
|
|
|
strcpy(message, "");
|
|
|
|
strcpy(message_priority, "");
|
2002-09-27 20:36:03 +00:00
|
|
|
send_global_prefs = false;
|
2003-04-03 18:35:40 +00:00
|
|
|
strcpy(code_sign_key, "");
|
|
|
|
strcpy(code_sign_key_signature, "");
|
2002-09-22 23:27:14 +00:00
|
|
|
memset(&user, 0, sizeof(user));
|
|
|
|
memset(&host, 0, sizeof(host));
|
2003-02-24 21:31:36 +00:00
|
|
|
memset(&team, 0, sizeof(team));
|
2002-12-02 04:29:40 +00:00
|
|
|
nucleus_only = false;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SCHEDULER_REPLY::~SCHEDULER_REPLY() {
|
|
|
|
}
|
|
|
|
|
|
|
|
int SCHEDULER_REPLY::write(FILE* fout) {
|
|
|
|
unsigned int i, j;
|
2002-12-02 04:29:40 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
fprintf(fout,
|
|
|
|
"<scheduler_reply>\n"
|
2002-12-02 04:29:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (request_delay) {
|
|
|
|
fprintf(fout, "<request_delay>%d</request_delay>\n", request_delay);
|
|
|
|
}
|
|
|
|
if (strlen(message)) {
|
|
|
|
fprintf(fout,
|
|
|
|
"<message priority=\"%s\">%s</message>\n",
|
|
|
|
message_priority,
|
|
|
|
message
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (nucleus_only) goto end;
|
|
|
|
|
|
|
|
fprintf(fout,
|
2003-02-14 22:35:35 +00:00
|
|
|
"<project_name>%s</project_name>\n",
|
|
|
|
gproject.long_name
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
fprintf(fout,
|
2003-02-14 22:35:35 +00:00
|
|
|
"<user_name>%s</user_name>\n"
|
|
|
|
"<user_total_credit>%f</user_total_credit>\n"
|
|
|
|
"<user_expavg_credit>%f</user_expavg_credit>\n"
|
2003-02-18 23:07:48 +00:00
|
|
|
"<user_create_time>%d</user_create_time>\n"
|
|
|
|
"<host_total_credit>%f</host_total_credit>\n"
|
2003-03-06 00:42:18 +00:00
|
|
|
"<host_expavg_credit>%f</host_expavg_credit>\n"
|
|
|
|
"<host_venue>%s</host_venue>\n",
|
2003-02-14 22:35:35 +00:00
|
|
|
user.name,
|
|
|
|
user.total_credit,
|
|
|
|
user.expavg_credit,
|
2003-02-18 23:07:48 +00:00
|
|
|
user.create_time,
|
|
|
|
host.total_credit,
|
2003-03-06 00:42:18 +00:00
|
|
|
host.expavg_credit,
|
|
|
|
host.venue
|
2002-08-26 22:57:17 +00:00
|
|
|
);
|
|
|
|
|
2003-02-24 21:31:36 +00:00
|
|
|
// might want to send team credit too.
|
|
|
|
//
|
|
|
|
if (team.id) {
|
|
|
|
fprintf(fout,
|
|
|
|
"<team_name>%s</team_name>\n",
|
|
|
|
team.name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
if (hostid) {
|
2002-10-22 21:44:16 +00:00
|
|
|
fprintf(fout,
|
2002-12-02 04:29:40 +00:00
|
|
|
"<hostid>%d</hostid>\n"
|
|
|
|
"<host_create_time>%d</host_create_time>\n",
|
|
|
|
hostid,
|
|
|
|
host.create_time
|
2003-02-14 22:35:35 +00:00
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 20:36:03 +00:00
|
|
|
if (send_global_prefs) {
|
|
|
|
fputs(user.global_prefs, fout);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-09-29 00:32:11 +00:00
|
|
|
// always send project prefs
|
|
|
|
//
|
|
|
|
fputs(user.project_prefs, fout);
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
// acknowledge results
|
|
|
|
//
|
|
|
|
for (i=0; i<result_acks.size(); i++) {
|
|
|
|
fprintf(fout,
|
|
|
|
"<result_ack>\n"
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
"</result_ack>\n",
|
|
|
|
result_acks[i].name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<apps.size(); i++) {
|
|
|
|
apps[i].write(fout);
|
|
|
|
}
|
2003-05-20 00:03:39 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
for (j=0; j<apps.size(); j++) {
|
|
|
|
if (apps[j].id == app_versions[i].appid) {
|
|
|
|
app_versions[i].write(fout, apps[j]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-20 00:03:39 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<wus.size(); i++) {
|
|
|
|
fputs(wus[i].xml_doc, fout);
|
|
|
|
}
|
2003-05-20 00:03:39 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
for (i=0; i<results.size(); i++) {
|
|
|
|
fputs(results[i].xml_doc_in, fout);
|
|
|
|
}
|
2003-05-20 00:03:39 +00:00
|
|
|
|
2003-04-03 18:35:40 +00:00
|
|
|
if (strlen(code_sign_key)) {
|
2002-07-07 20:39:24 +00:00
|
|
|
fputs("<code_sign_key>\n", fout);
|
|
|
|
fputs(code_sign_key, fout);
|
|
|
|
fputs("</code_sign_key>\n", fout);
|
|
|
|
}
|
2003-05-20 00:03:39 +00:00
|
|
|
|
2003-04-03 18:35:40 +00:00
|
|
|
if (strlen(code_sign_key_signature)) {
|
2002-07-07 20:39:24 +00:00
|
|
|
fputs("<code_sign_key_signature>\n", fout);
|
|
|
|
fputs(code_sign_key_signature, fout);
|
|
|
|
fputs("</code_sign_key_signature>\n", fout);
|
|
|
|
}
|
2002-12-02 04:29:40 +00:00
|
|
|
end:
|
2002-04-30 22:22:54 +00:00
|
|
|
fprintf(fout,
|
|
|
|
"</scheduler_reply>\n"
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SCHEDULER_REPLY::insert_app_unique(APP& app) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<apps.size(); i++) {
|
|
|
|
if (app.id == apps[i].id) return;
|
|
|
|
}
|
|
|
|
apps.push_back(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SCHEDULER_REPLY::insert_app_version_unique(APP_VERSION& av) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<app_versions.size(); i++) {
|
|
|
|
if (av.id == app_versions[i].id) return;
|
|
|
|
}
|
|
|
|
app_versions.push_back(av);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SCHEDULER_REPLY::insert_workunit_unique(WORKUNIT& wu) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0; i<wus.size(); i++) {
|
|
|
|
if (wu.id == wus[i].id) return;
|
|
|
|
}
|
|
|
|
wus.push_back(wu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SCHEDULER_REPLY::insert_result(RESULT& result) {
|
|
|
|
results.push_back(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
int APP::write(FILE* fout) {
|
|
|
|
fprintf(fout,
|
|
|
|
"<app>\n"
|
|
|
|
" <name>%s</name>\n"
|
|
|
|
"</app>\n",
|
2002-07-29 00:39:45 +00:00
|
|
|
name
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int APP_VERSION::write(FILE* fout, APP& app) {
|
2002-05-17 22:33:57 +00:00
|
|
|
fputs(xml_doc, fout);
|
2002-04-30 22:22:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RESULT::parse_from_client(FILE* fin) {
|
2003-01-07 01:02:08 +00:00
|
|
|
char buf[256], ebuf[256];
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
memset(this, 0, sizeof(RESULT));
|
|
|
|
while (fgets(buf, 256, fin)) {
|
|
|
|
if (match_tag(buf, "</result>")) return 0;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<name>", name, sizeof(name))) continue;
|
2003-02-20 22:09:29 +00:00
|
|
|
else if (parse_int(buf, "<state>", client_state)) continue;
|
2002-08-12 00:38:31 +00:00
|
|
|
else if (parse_double(buf, "<final_cpu_time>", cpu_time)) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (match_tag(buf, "<file_info>")) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcat(xml_doc_out, buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
while (fgets(buf, 256, fin)) {
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcat(xml_doc_out, buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
if (match_tag(buf, "</file_info>")) break;
|
|
|
|
}
|
|
|
|
continue;
|
2003-04-03 18:35:40 +00:00
|
|
|
} else if (match_tag(buf, "<stderr_out>" )) {
|
2002-04-30 22:22:54 +00:00
|
|
|
while (fgets(buf, 256, fin)) {
|
|
|
|
if (match_tag(buf, "</stderr_out>")) break;
|
2003-04-03 18:35:40 +00:00
|
|
|
safe_strcat(stderr_out, buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
continue;
|
2003-04-03 18:35:40 +00:00
|
|
|
} else {
|
2003-01-07 01:02:08 +00:00
|
|
|
sprintf(ebuf, "RESULT::parse_from_client(): unrecognized: %s\n", buf);
|
|
|
|
write_log(ebuf);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HOST::parse(FILE* fin) {
|
2003-01-07 01:02:08 +00:00
|
|
|
char buf[256], ebuf[256];
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
while (fgets(buf, 256, fin)) {
|
|
|
|
if (match_tag(buf, "</host_info>")) return 0;
|
|
|
|
else if (parse_int(buf, "<timezone>", timezone)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
else if (parse_str(buf, "<domain_name>", domain_name, sizeof(domain_name))) continue;
|
|
|
|
else if (parse_str(buf, "<serialnum>", serialnum, sizeof(serialnum))) continue;
|
|
|
|
else if (parse_str(buf, "<ip_addr>", last_ip_addr, sizeof(last_ip_addr))) continue;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_int(buf, "<p_ncpus>", p_ncpus)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
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;
|
2002-04-30 22:22:54 +00:00
|
|
|
else if (parse_double(buf, "<p_fpops>", p_fpops)) continue;
|
|
|
|
else if (parse_double(buf, "<p_iops>", p_iops)) continue;
|
|
|
|
else if (parse_double(buf, "<p_membw>", p_membw)) continue;
|
2002-06-21 18:31:32 +00:00
|
|
|
else if (parse_double(buf, "<p_calculated>", p_calculated)) continue;
|
2002-09-22 23:27:14 +00:00
|
|
|
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;
|
2002-04-30 22:22:54 +00:00
|
|
|
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_double(buf, "<n_bwup>", n_bwup)) continue;
|
|
|
|
else if (parse_double(buf, "<n_bwdown>", n_bwdown)) continue;
|
2003-01-07 01:02:08 +00:00
|
|
|
else {
|
|
|
|
sprintf(ebuf, "HOST::parse(): unrecognized: %s\n", buf);
|
|
|
|
write_log(ebuf);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int HOST::parse_time_stats(FILE* fin) {
|
2003-01-07 01:02:08 +00:00
|
|
|
char buf[256], ebuf[256];
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
while (fgets(buf, 256, fin)) {
|
|
|
|
if (match_tag(buf, "</time_stats>")) return 0;
|
|
|
|
else if (parse_double(buf, "<on_frac>", on_frac)) continue;
|
|
|
|
else if (parse_double(buf, "<connected_frac>", connected_frac)) continue;
|
|
|
|
else if (parse_double(buf, "<active_frac>", active_frac)) continue;
|
2003-01-07 01:02:08 +00:00
|
|
|
else {
|
|
|
|
sprintf(ebuf, "HOST::parse_time_stats(): unrecognized: %s\n", buf);
|
|
|
|
write_log(ebuf);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HOST::parse_net_stats(FILE* fin) {
|
2003-01-07 01:02:08 +00:00
|
|
|
char buf[256], ebuf[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
while (fgets(buf, 256, fin)) {
|
|
|
|
if (match_tag(buf, "</net_stats>")) return 0;
|
|
|
|
else if (parse_double(buf, "<bwup>", n_bwup)) continue;
|
|
|
|
else if (parse_double(buf, "<bwdown>", n_bwdown)) continue;
|
2003-01-07 01:02:08 +00:00
|
|
|
else {
|
|
|
|
sprintf(ebuf, "HOST::parse_net_stats(): unrecognized: %s\n", buf);
|
|
|
|
write_log(ebuf);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2003-05-20 00:03:39 +00:00
|
|
|
|
|
|
|
int APP_FILE::parse(char*& in) {
|
|
|
|
char buf[256], ebuf[256];
|
|
|
|
|
|
|
|
while (sgets(buf, 256, in)) {
|
|
|
|
if (match_tag(buf, "</app_file>")) return 0;
|
|
|
|
else if (parse_str(buf, "<url>", url, sizeof(url))) continue;
|
|
|
|
else if (parse_str(buf, "<open_name>", open_name, sizeof(open_name))) continue;
|
|
|
|
else {
|
|
|
|
sprintf(ebuf, "APP_FILE::parse(): unrecognized %s\n", buf);
|
|
|
|
write_log(ebuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|