2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-10-29 11:05:39 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2003-10-29 11:05:39 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2003-07-01 20:37:09 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2003-07-01 20:37:09 +00:00
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstring>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2003-05-07 23:42:17 +00:00
|
|
|
|
2004-06-08 14:37:42 +00:00
|
|
|
#include "boinc_api.h"
|
2003-05-07 23:42:17 +00:00
|
|
|
#include "parse.h"
|
2003-06-14 20:24:29 +00:00
|
|
|
#include "error_numbers.h"
|
2003-05-07 23:42:17 +00:00
|
|
|
#include "util.h"
|
2004-05-19 23:16:19 +00:00
|
|
|
#include "filesys.h"
|
2004-06-16 19:21:11 +00:00
|
|
|
#include "miofile.h"
|
2003-05-07 23:42:17 +00:00
|
|
|
|
|
|
|
#include "app_ipc.h"
|
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
const char* xml_graphics_modes[NGRAPHICS_MSGS] = {
|
2003-05-09 20:33:57 +00:00
|
|
|
"<mode_unsupported/>",
|
|
|
|
"<mode_hide_graphics/>",
|
|
|
|
"<mode_window/>",
|
|
|
|
"<mode_fullscreen/>",
|
2004-07-08 03:38:52 +00:00
|
|
|
"<mode_blankscreen/>",
|
2004-11-17 09:27:06 +00:00
|
|
|
"<reread_prefs/>",
|
2004-11-17 20:06:44 +00:00
|
|
|
"<mode_quit/>"
|
2003-05-07 23:42:17 +00:00
|
|
|
};
|
|
|
|
|
2004-11-17 19:19:26 +00:00
|
|
|
GRAPHICS_MSG::GRAPHICS_MSG() {
|
|
|
|
memset(this, 0, sizeof(GRAPHICS_MSG));
|
|
|
|
}
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
APP_INIT_DATA::APP_INIT_DATA() {
|
|
|
|
project_preferences = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
APP_INIT_DATA::~APP_INIT_DATA() {
|
|
|
|
if (project_preferences) free(project_preferences);
|
|
|
|
}
|
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
int write_init_data_file(FILE* f, APP_INIT_DATA& ai) {
|
2004-02-02 22:17:48 +00:00
|
|
|
string str1, str2;
|
2004-08-23 22:44:53 +00:00
|
|
|
fprintf(f, "<app_init_data>\n<core_version>%d</core_version>\n", ai.core_version);
|
2003-09-27 17:53:43 +00:00
|
|
|
if (strlen(ai.app_name)) {
|
|
|
|
fprintf(f, "<app_name>%s</app_name>\n", ai.app_name);
|
|
|
|
}
|
2004-10-06 19:09:37 +00:00
|
|
|
if (ai.project_preferences && strlen(ai.project_preferences)) {
|
2004-04-23 23:01:04 +00:00
|
|
|
fprintf(f, "<project_preferences>\n%s</project_preferences>\n", ai.project_preferences);
|
2003-05-07 23:42:17 +00:00
|
|
|
}
|
|
|
|
if (strlen(ai.team_name)) {
|
2004-02-02 22:17:48 +00:00
|
|
|
str1 = ai.team_name;
|
|
|
|
xml_escape(str1, str2);
|
|
|
|
fprintf(f, "<team_name>%s</team_name>\n", str2.c_str());
|
2003-05-07 23:42:17 +00:00
|
|
|
}
|
|
|
|
if (strlen(ai.user_name)) {
|
2004-02-02 22:17:48 +00:00
|
|
|
str1 = ai.user_name;
|
|
|
|
xml_escape(str1, str2);
|
|
|
|
fprintf(f, "<user_name>%s</user_name>\n", str2.c_str());
|
2003-05-07 23:42:17 +00:00
|
|
|
}
|
2004-04-23 00:05:16 +00:00
|
|
|
if (strlen(ai.project_dir)) {
|
|
|
|
fprintf(f, "<project_dir>%s</project_dir>\n", ai.project_dir);
|
|
|
|
}
|
2004-04-23 22:51:28 +00:00
|
|
|
if (strlen(ai.boinc_dir)) {
|
|
|
|
fprintf(f, "<boinc_dir>%s</boinc_dir>\n", ai.boinc_dir);
|
|
|
|
}
|
|
|
|
if (strlen(ai.authenticator)) {
|
|
|
|
fprintf(f, "<authenticator>%s</authenticator>\n", ai.authenticator);
|
|
|
|
}
|
2004-04-23 00:05:16 +00:00
|
|
|
if (strlen(ai.wu_name)) {
|
|
|
|
fprintf(f, "<wu_name>%s</wu_name>\n", ai.wu_name);
|
|
|
|
}
|
2004-03-27 00:23:19 +00:00
|
|
|
#ifdef _WIN32
|
2004-08-31 21:02:17 +00:00
|
|
|
if (strlen(ai.shmem_seg_name)) {
|
|
|
|
fprintf(f, "<comm_obj_name>%s</comm_obj_name>\n", ai.shmem_seg_name);
|
2003-05-07 23:42:17 +00:00
|
|
|
}
|
2004-04-23 00:05:16 +00:00
|
|
|
#else
|
2004-08-31 21:02:17 +00:00
|
|
|
fprintf(f, "<shm_key>%d</shm_key>\n", ai.shmem_seg_name);
|
2004-03-27 00:23:19 +00:00
|
|
|
#endif
|
2003-05-07 23:42:17 +00:00
|
|
|
fprintf(f,
|
2004-04-23 22:51:28 +00:00
|
|
|
"<slot>%d</slot>\n"
|
2003-05-07 23:42:17 +00:00
|
|
|
"<wu_cpu_time>%f</wu_cpu_time>\n"
|
|
|
|
"<user_total_credit>%f</user_total_credit>\n"
|
|
|
|
"<user_expavg_credit>%f</user_expavg_credit>\n"
|
|
|
|
"<host_total_credit>%f</host_total_credit>\n"
|
|
|
|
"<host_expavg_credit>%f</host_expavg_credit>\n"
|
|
|
|
"<checkpoint_period>%f</checkpoint_period>\n"
|
2004-05-24 04:03:34 +00:00
|
|
|
"<fraction_done_update_period>%f</fraction_done_update_period>\n"
|
2004-06-16 19:21:11 +00:00
|
|
|
"<fraction_done_start>%f</fraction_done_start>\n"
|
|
|
|
"<fraction_done_end>%f</fraction_done_end>\n",
|
2004-04-23 22:51:28 +00:00
|
|
|
ai.slot,
|
2003-05-07 23:42:17 +00:00
|
|
|
ai.wu_cpu_time,
|
|
|
|
ai.user_total_credit,
|
|
|
|
ai.user_expavg_credit,
|
|
|
|
ai.host_total_credit,
|
|
|
|
ai.host_expavg_credit,
|
|
|
|
ai.checkpoint_period,
|
2004-05-24 04:03:34 +00:00
|
|
|
ai.fraction_done_update_period,
|
|
|
|
ai.fraction_done_start,
|
|
|
|
ai.fraction_done_end
|
2003-05-07 23:42:17 +00:00
|
|
|
);
|
2004-06-16 19:21:11 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(f);
|
|
|
|
ai.host_info.write(mf);
|
2004-10-06 19:09:37 +00:00
|
|
|
ai.proxy_info.write(mf);
|
|
|
|
ai.global_prefs.write(f);
|
|
|
|
fprintf(f, "</app_init_data>\n");
|
2003-05-07 23:42:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int parse_init_data_file(FILE* f, APP_INIT_DATA& ai) {
|
|
|
|
char buf[256];
|
2004-10-06 19:09:37 +00:00
|
|
|
int retval;
|
|
|
|
bool flag;
|
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
memset(&ai, 0, sizeof(ai));
|
2004-05-24 04:03:34 +00:00
|
|
|
ai.fraction_done_start = 0;
|
|
|
|
ai.fraction_done_end = 1;
|
2003-05-07 23:42:17 +00:00
|
|
|
while (fgets(buf, 256, f)) {
|
2004-04-23 23:01:04 +00:00
|
|
|
if (match_tag(buf, "<project_preferences>")) {
|
2004-10-06 19:09:37 +00:00
|
|
|
retval = dup_element_contents(f, "</project_preferences>", &ai.project_preferences);
|
|
|
|
if (retval) return retval;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (match_tag(buf, "<global_preferences>")) {
|
|
|
|
retval = ai.global_prefs.parse(f, "", flag);
|
|
|
|
if (retval) return retval;
|
2003-05-07 23:42:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-06-16 19:21:11 +00:00
|
|
|
else if (match_tag(buf, "<host_info>")) {
|
|
|
|
MIOFILE mf;
|
|
|
|
mf.init_file(f);
|
|
|
|
ai.host_info.parse(mf);
|
|
|
|
continue;
|
|
|
|
}
|
2004-08-03 09:50:24 +00:00
|
|
|
else if (parse_int(buf, "<core_version>", ai.core_version)) continue;
|
2003-09-27 17:53:43 +00:00
|
|
|
else if (parse_str(buf, "<app_name>", ai.app_name, sizeof(ai.app_name))) continue;
|
2003-05-07 23:42:17 +00:00
|
|
|
else if (parse_str(buf, "<user_name>", ai.user_name, sizeof(ai.user_name))) continue;
|
|
|
|
else if (parse_str(buf, "<team_name>", ai.team_name, sizeof(ai.team_name))) continue;
|
2004-04-23 00:05:16 +00:00
|
|
|
else if (parse_str(buf, "<project_dir>", ai.project_dir, sizeof(ai.project_dir))) continue;
|
2004-04-23 22:51:28 +00:00
|
|
|
else if (parse_str(buf, "<boinc_dir>", ai.boinc_dir, sizeof(ai.boinc_dir))) continue;
|
|
|
|
else if (parse_str(buf, "<authenticator>", ai.authenticator, sizeof(ai.authenticator))) continue;
|
2004-04-23 00:05:16 +00:00
|
|
|
else if (parse_str(buf, "<wu_name>", ai.wu_name, sizeof(ai.wu_name))) continue;
|
2004-03-31 19:43:15 +00:00
|
|
|
#ifdef _WIN32
|
2004-08-31 21:02:17 +00:00
|
|
|
else if (parse_str(buf, "<comm_obj_name>", ai.shmem_seg_name, sizeof(ai.shmem_seg_name))) continue;
|
2004-04-23 00:05:16 +00:00
|
|
|
#else
|
2004-08-31 21:02:17 +00:00
|
|
|
else if (parse_int(buf, "<shm_key>", ai.shmem_seg_name)) continue;
|
2004-03-31 19:43:15 +00:00
|
|
|
#endif
|
2004-04-23 22:51:28 +00:00
|
|
|
else if (parse_int(buf, "<slot>", ai.slot)) continue;
|
2003-05-07 23:42:17 +00:00
|
|
|
else if (parse_double(buf, "<user_total_credit>", ai.user_total_credit)) continue;
|
|
|
|
else if (parse_double(buf, "<user_expavg_credit>", ai.user_expavg_credit)) continue;
|
|
|
|
else if (parse_double(buf, "<host_total_credit>", ai.host_total_credit)) continue;
|
|
|
|
else if (parse_double(buf, "<host_expavg_credit>", ai.host_expavg_credit)) continue;
|
|
|
|
else if (parse_double(buf, "<wu_cpu_time>", ai.wu_cpu_time)) continue;
|
|
|
|
else if (parse_double(buf, "<checkpoint_period>", ai.checkpoint_period)) continue;
|
|
|
|
else if (parse_double(buf, "<fraction_done_update_period>", ai.fraction_done_update_period)) continue;
|
2004-05-24 04:03:34 +00:00
|
|
|
else if (parse_double(buf, "<fraction_done_start>", ai.fraction_done_start)) continue;
|
|
|
|
else if (parse_double(buf, "<fraction_done_end>", ai.fraction_done_end)) continue;
|
2004-04-14 23:32:17 +00:00
|
|
|
//else fprintf(stderr, "parse_init_data_file: unrecognized %s", buf);
|
2003-05-07 23:42:17 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-02-09 05:11:05 +00:00
|
|
|
APP_CLIENT_SHM::APP_CLIENT_SHM() {
|
|
|
|
shm = 0;
|
|
|
|
}
|
2004-07-08 03:38:52 +00:00
|
|
|
bool MSG_CHANNEL::get_msg(char *msg) {
|
|
|
|
if (!buf[0]) return false;
|
|
|
|
safe_strncpy(msg, buf+1, MSG_CHANNEL_SIZE-1);
|
|
|
|
buf[0] = 0;
|
2003-05-09 20:33:57 +00:00
|
|
|
return true;
|
2003-05-07 23:42:17 +00:00
|
|
|
}
|
|
|
|
|
2004-10-14 22:01:05 +00:00
|
|
|
bool MSG_CHANNEL::has_msg() {
|
|
|
|
if (buf[0]) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
bool MSG_CHANNEL::send_msg(const char *msg) {
|
2004-07-08 03:38:52 +00:00
|
|
|
if (buf[0]) return false;
|
|
|
|
safe_strncpy(buf+1, msg, MSG_CHANNEL_SIZE-1);
|
|
|
|
buf[0] = 1;
|
2003-05-09 20:33:57 +00:00
|
|
|
return true;
|
2003-05-07 23:42:17 +00:00
|
|
|
}
|
|
|
|
|
2005-02-16 23:17:43 +00:00
|
|
|
void MSG_CHANNEL::send_msg_overwrite(const char* msg) {
|
2004-08-23 22:06:48 +00:00
|
|
|
safe_strncpy(buf+1, msg, MSG_CHANNEL_SIZE-1);
|
|
|
|
buf[0] = 1;
|
|
|
|
}
|
2003-05-07 23:42:17 +00:00
|
|
|
|
2004-11-17 19:19:26 +00:00
|
|
|
int APP_CLIENT_SHM::decode_graphics_msg(char* msg, GRAPHICS_MSG& m) {
|
2003-05-09 20:33:57 +00:00
|
|
|
int i;
|
2004-11-17 09:27:06 +00:00
|
|
|
|
2004-11-17 19:19:26 +00:00
|
|
|
parse_str(msg, "<window_station>", m.window_station, sizeof(m.window_station));
|
|
|
|
parse_str(msg, "<desktop>", m.desktop, sizeof(m.desktop));
|
2005-02-15 06:32:43 +00:00
|
|
|
parse_str(msg, "<display>", m.display, sizeof(m.display));
|
2004-11-17 09:27:06 +00:00
|
|
|
|
2004-11-17 19:19:26 +00:00
|
|
|
m.mode = 0;
|
2004-07-08 03:38:52 +00:00
|
|
|
for (i=0; i<NGRAPHICS_MSGS; i++) {
|
2004-11-17 19:19:26 +00:00
|
|
|
if (match_tag(msg, xml_graphics_modes[i])) {
|
|
|
|
m.mode = i;
|
2003-05-09 20:33:57 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-08 03:38:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void APP_CLIENT_SHM::reset_msgs() {
|
|
|
|
memset(shm, 0, sizeof(SHARED_MEM));
|
2003-05-07 23:42:17 +00:00
|
|
|
}
|
|
|
|
|
2003-06-14 20:24:29 +00:00
|
|
|
// create a file (new_link) which contains an XML
|
|
|
|
// reference to existing file.
|
|
|
|
//
|
2003-10-29 11:05:39 +00:00
|
|
|
int boinc_link(const char *existing, const char *new_link) {
|
2003-06-14 20:24:29 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = fopen(new_link, "w");
|
|
|
|
if (!fp) return ERR_FOPEN;
|
|
|
|
fprintf(fp, "<soft_link>%s</soft_link>\n", existing);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// resolve XML soft link
|
|
|
|
//
|
2003-10-29 11:05:39 +00:00
|
|
|
int boinc_resolve_filename(const char *virtual_name, char *physical_name, int len) {
|
2003-06-14 20:24:29 +00:00
|
|
|
FILE *fp;
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
safe_strncpy(physical_name, virtual_name, len);
|
|
|
|
|
|
|
|
// Open the file and load the first line
|
2004-05-19 23:16:19 +00:00
|
|
|
//
|
|
|
|
fp = boinc_fopen(virtual_name, "r");
|
2004-01-30 22:19:19 +00:00
|
|
|
if (!fp) return ERR_FOPEN;
|
2003-06-14 20:24:29 +00:00
|
|
|
|
2004-10-07 19:18:37 +00:00
|
|
|
// must initialize buf since fgets() on an empty file won't do anything
|
|
|
|
//
|
|
|
|
buf[0] = 0;
|
2003-06-14 20:24:29 +00:00
|
|
|
fgets(buf, 512, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
// If it's the <soft_link> XML tag, return its value,
|
|
|
|
// otherwise, return the original file name
|
|
|
|
//
|
|
|
|
parse_str(buf, "<soft_link>", physical_name, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-29 11:05:39 +00:00
|
|
|
|
|
|
|
// resolve XML soft link
|
|
|
|
//
|
2004-06-08 14:37:42 +00:00
|
|
|
int boinc_resolve_filename_s(const char *virtual_name, string& physical_name) {
|
2003-11-01 00:45:07 +00:00
|
|
|
|
|
|
|
physical_name = virtual_name;
|
2003-10-29 11:05:39 +00:00
|
|
|
// Open the file and load the first line
|
|
|
|
FILE *fp = fopen(virtual_name, "r");
|
2004-01-30 22:19:19 +00:00
|
|
|
if (!fp) return ERR_FOPEN;
|
2003-11-03 03:18:13 +00:00
|
|
|
|
2003-10-29 11:05:39 +00:00
|
|
|
char buf[512];
|
|
|
|
fgets(buf, 512, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
// If it's the <soft_link> XML tag, return its value,
|
|
|
|
// otherwise, return the original file name
|
|
|
|
//
|
|
|
|
parse_str(buf, "<soft_link>", physical_name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_3add42d20e = "$Id$";
|