2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2003-06-11 22:42:49 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
2003-06-11 22:42:49 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// 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-06-11 22:42:49 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2003-06-11 22:42:49 +00:00
|
|
|
|
2004-03-05 04:37:53 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2010-10-29 18:58:26 +00:00
|
|
|
#define snprintf _snprintf
|
2005-11-21 18:34:44 +00:00
|
|
|
#else
|
|
|
|
#include "config.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdarg>
|
2007-12-21 21:09:40 +00:00
|
|
|
#include <cstring>
|
2004-09-30 21:41:09 +00:00
|
|
|
#include <deque>
|
2004-04-08 08:15:23 +00:00
|
|
|
#endif
|
2008-08-12 22:30:37 +00:00
|
|
|
#include "str_util.h"
|
2004-03-05 04:37:53 +00:00
|
|
|
|
2004-09-30 21:41:09 +00:00
|
|
|
using std::deque;
|
|
|
|
|
2010-10-18 20:09:51 +00:00
|
|
|
#include "diagnostics.h"
|
2003-06-11 22:42:49 +00:00
|
|
|
#include "log_flags.h"
|
2009-06-16 20:54:44 +00:00
|
|
|
#include "str_replace.h"
|
2009-12-23 19:52:34 +00:00
|
|
|
|
2005-01-28 19:01:08 +00:00
|
|
|
#include "client_types.h"
|
2009-12-23 21:22:24 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
#include "cs_notice.h"
|
2009-12-23 19:52:34 +00:00
|
|
|
#include "main.h"
|
2003-06-11 22:42:49 +00:00
|
|
|
|
2009-12-23 19:52:34 +00:00
|
|
|
#include "client_msgs.h"
|
2004-06-17 04:49:34 +00:00
|
|
|
|
2009-12-23 19:52:34 +00:00
|
|
|
MESSAGE_DESCS message_descs;
|
2004-04-08 08:15:23 +00:00
|
|
|
|
2010-10-19 15:48:33 +00:00
|
|
|
#ifdef SIM
|
|
|
|
extern void show_message(
|
|
|
|
PROJECT *p, char* msg, int priority, bool is_html, const char* link
|
|
|
|
);
|
|
|
|
#else
|
2010-10-18 20:09:51 +00:00
|
|
|
// Show a message:
|
|
|
|
// 1) As a MESSAGE_DESC (for GUI event log)
|
|
|
|
// 2) As a NOTICE, if high priority (for GUI notices)
|
|
|
|
// 3) write to log file (stdoutdae.txt)
|
|
|
|
//
|
|
|
|
void show_message(PROJECT *p, char* msg, int priority, bool is_html, const char* link) {
|
|
|
|
const char* x;
|
2010-10-29 18:58:26 +00:00
|
|
|
char message[1024], event_msg[1024];
|
2010-10-18 20:09:51 +00:00
|
|
|
char* time_string = time_to_string(gstate.now);
|
|
|
|
|
|
|
|
// Cycle the log files if needed
|
|
|
|
//
|
|
|
|
diagnostics_cycle_logs();
|
|
|
|
|
2010-10-29 18:58:26 +00:00
|
|
|
strlcpy(message, msg, sizeof(message));
|
2010-10-18 20:09:51 +00:00
|
|
|
|
|
|
|
// trim trailing \n's
|
|
|
|
//
|
2010-10-29 18:58:26 +00:00
|
|
|
while (strlen(message) && message[strlen(message)-1] == '\n') {
|
2010-10-18 20:09:51 +00:00
|
|
|
message[strlen(message)-1] = 0;
|
|
|
|
}
|
|
|
|
|
2010-10-29 18:58:26 +00:00
|
|
|
switch (priority) {
|
|
|
|
case MSG_INTERNAL_ERROR:
|
|
|
|
snprintf(event_msg, sizeof(event_msg), "[error] %s", message);
|
|
|
|
break;
|
|
|
|
case MSG_SCHEDULER_ALERT:
|
2010-12-17 18:56:10 +00:00
|
|
|
snprintf(event_msg, sizeof(event_msg), "%s: %s",
|
|
|
|
_("Message from server"), message
|
2010-10-29 18:58:26 +00:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strlcpy(event_msg, message, sizeof(event_msg));
|
2010-10-18 20:09:51 +00:00
|
|
|
}
|
2010-10-29 18:58:26 +00:00
|
|
|
message_descs.insert(p, priority, (int)gstate.now, event_msg);
|
2010-10-18 20:09:51 +00:00
|
|
|
|
|
|
|
switch (priority) {
|
|
|
|
case MSG_USER_ALERT:
|
|
|
|
case MSG_SCHEDULER_ALERT:
|
|
|
|
char buf[1024];
|
|
|
|
if (is_html) {
|
|
|
|
xml_escape(message, buf, 1024);
|
|
|
|
} else {
|
|
|
|
char buf2[1024];
|
|
|
|
xml_escape(message, buf2, 1024);
|
|
|
|
xml_escape(buf2, buf, 1024);
|
|
|
|
}
|
|
|
|
NOTICE n;
|
|
|
|
n.description = buf;
|
|
|
|
if (link) {
|
|
|
|
strcpy(n.link, link);
|
|
|
|
}
|
|
|
|
if (p) {
|
|
|
|
strcpy(n.project_name, p->get_project_name());
|
|
|
|
}
|
|
|
|
n.create_time = n.arrival_time = gstate.now;
|
|
|
|
strcpy(n.category, (priority==MSG_USER_ALERT)?"client":"scheduler");
|
|
|
|
notices.append(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
strip_translation(message);
|
|
|
|
|
2010-10-29 18:58:26 +00:00
|
|
|
if (p) {
|
|
|
|
x = p->get_project_name();
|
|
|
|
} else {
|
|
|
|
x = "---";
|
|
|
|
}
|
2010-10-18 20:09:51 +00:00
|
|
|
printf("%s [%s] %s\n", time_string, x, message);
|
|
|
|
#ifdef _WIN32
|
2010-10-29 18:58:26 +00:00
|
|
|
if (gstate.executing_as_daemon) {
|
2010-10-18 20:09:51 +00:00
|
|
|
char event_message[2048];
|
|
|
|
sprintf(event_message, "%s [%s] %s\n", time_string, x, message);
|
|
|
|
::OutputDebugString(event_message);
|
|
|
|
}
|
2010-10-29 18:58:26 +00:00
|
|
|
#endif
|
2010-10-18 20:09:51 +00:00
|
|
|
}
|
2010-10-19 15:48:33 +00:00
|
|
|
#endif
|
2010-10-18 20:09:51 +00:00
|
|
|
|
2004-04-08 08:15:23 +00:00
|
|
|
// Takes a printf style formatted string, inserts the proper values,
|
|
|
|
// and passes it to show_message
|
|
|
|
//
|
2005-02-16 23:17:43 +00:00
|
|
|
void msg_printf(PROJECT *p, int priority, const char *fmt, ...) {
|
2009-12-23 21:22:24 +00:00
|
|
|
char buf[8192]; // output can be much longer than format
|
|
|
|
va_list ap;
|
2004-04-08 08:15:23 +00:00
|
|
|
|
|
|
|
if (fmt == NULL) return;
|
|
|
|
|
2008-08-12 19:06:35 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
buf[sizeof(buf)-1] = 0;
|
|
|
|
va_end(ap);
|
2004-04-08 08:15:23 +00:00
|
|
|
|
2010-10-18 20:09:51 +00:00
|
|
|
show_message(p, buf, priority, true, 0);
|
2010-07-21 19:04:46 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 20:09:51 +00:00
|
|
|
void msg_printf_notice(PROJECT *p, bool is_html, const char* link, const char *fmt, ...) {
|
2010-07-21 19:04:46 +00:00
|
|
|
char buf[8192]; // output can be much longer than format
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (fmt == NULL) return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
|
|
|
buf[sizeof(buf)-1] = 0;
|
|
|
|
va_end(ap);
|
|
|
|
|
2010-10-18 20:09:51 +00:00
|
|
|
show_message(p, buf, MSG_USER_ALERT, is_html, link);
|
2004-04-08 08:15:23 +00:00
|
|
|
}
|
2004-06-17 04:49:34 +00:00
|
|
|
|
2009-12-23 21:22:24 +00:00
|
|
|
// handle new message:
|
|
|
|
// add to cache, and delete old messages if cache too big.
|
|
|
|
// If high priority, create a notice.
|
2004-06-17 04:49:34 +00:00
|
|
|
//
|
2010-08-26 21:26:52 +00:00
|
|
|
void MESSAGE_DESCS::insert(
|
2010-10-18 20:09:51 +00:00
|
|
|
PROJECT* p, int priority, int now, char* message
|
2010-08-26 21:26:52 +00:00
|
|
|
) {
|
2004-06-17 04:49:34 +00:00
|
|
|
MESSAGE_DESC* mdp = new MESSAGE_DESC;
|
|
|
|
static int seqno = 1;
|
2005-01-28 19:01:08 +00:00
|
|
|
strcpy(mdp->project_name, "");
|
|
|
|
if (p) {
|
2008-08-12 19:06:35 +00:00
|
|
|
strlcpy(
|
2008-08-12 22:19:50 +00:00
|
|
|
mdp->project_name, p->get_project_name(), sizeof(mdp->project_name)
|
2008-08-12 19:06:35 +00:00
|
|
|
);
|
2005-01-28 19:01:08 +00:00
|
|
|
}
|
2010-08-26 21:26:52 +00:00
|
|
|
mdp->priority = (priority==MSG_SCHEDULER_ALERT)?MSG_USER_ALERT:priority;
|
2004-06-17 04:49:34 +00:00
|
|
|
mdp->timestamp = now;
|
|
|
|
mdp->seqno = seqno++;
|
|
|
|
mdp->message = message;
|
2009-12-23 19:52:34 +00:00
|
|
|
while (msgs.size() > MAX_SAVED_MESSAGES) {
|
|
|
|
delete msgs.back();
|
|
|
|
msgs.pop_back();
|
|
|
|
}
|
|
|
|
msgs.push_front(mdp);
|
2009-12-23 21:22:24 +00:00
|
|
|
}
|
2009-12-23 19:52:34 +00:00
|
|
|
|
2010-07-14 21:23:17 +00:00
|
|
|
void MESSAGE_DESCS::write(int seqno, MIOFILE& fout, bool translatable) {
|
2009-12-23 19:52:34 +00:00
|
|
|
int i, j;
|
|
|
|
unsigned int k;
|
|
|
|
MESSAGE_DESC* mdp;
|
2010-07-14 21:23:17 +00:00
|
|
|
char buf[1024];
|
2009-12-23 19:52:34 +00:00
|
|
|
|
|
|
|
// messages are stored in descreasing seqno,
|
|
|
|
// i.e. newer ones are at the head of the vector.
|
|
|
|
// compute j = index of first message to return
|
|
|
|
//
|
|
|
|
j = (int)msgs.size()-1;
|
|
|
|
for (k=0; k<msgs.size(); k++) {
|
|
|
|
mdp = msgs[k];
|
|
|
|
if (mdp->seqno <= seqno) {
|
|
|
|
j = k-1;
|
|
|
|
break;
|
|
|
|
}
|
2004-06-17 04:49:34 +00:00
|
|
|
}
|
2009-12-23 19:52:34 +00:00
|
|
|
|
|
|
|
fout.printf("<msgs>\n");
|
|
|
|
for (i=j; i>=0; i--) {
|
|
|
|
mdp = msgs[i];
|
2010-07-15 17:30:03 +00:00
|
|
|
strcpy(buf, mdp->message.c_str());
|
|
|
|
if (!translatable) {
|
|
|
|
strip_translation(buf);
|
|
|
|
}
|
2009-12-23 19:52:34 +00:00
|
|
|
fout.printf(
|
|
|
|
"<msg>\n"
|
|
|
|
" <project>%s</project>\n"
|
|
|
|
" <pri>%d</pri>\n"
|
|
|
|
" <seqno>%d</seqno>\n"
|
|
|
|
" <body>\n%s\n</body>\n"
|
|
|
|
" <time>%d</time>\n",
|
|
|
|
mdp->project_name,
|
|
|
|
mdp->priority,
|
|
|
|
mdp->seqno,
|
2010-07-14 21:23:17 +00:00
|
|
|
buf,
|
2009-12-23 19:52:34 +00:00
|
|
|
mdp->timestamp
|
|
|
|
);
|
|
|
|
fout.printf("</msg>\n");
|
|
|
|
}
|
|
|
|
fout.printf("</msgs>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int MESSAGE_DESCS::highest_seqno() {
|
|
|
|
if (msgs.size()) return msgs[0]->seqno;
|
|
|
|
return 0;
|
2004-06-17 05:08:31 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2010-05-11 20:18:57 +00:00
|
|
|
void MESSAGE_DESCS::cleanup() {
|
|
|
|
for (unsigned int i=0; i<msgs.size(); i++) {
|
|
|
|
delete msgs[i];
|
|
|
|
}
|
|
|
|
msgs.clear();
|
|
|
|
}
|