- lib: fixup notice RPCs to make them manager compatible.

- lib: remove memset from notice constructor, bad things can happen
        when you null out a std::string structure.
        
    lib/
        gui_rpc_client.h
        gui_rpc_client_ops.cpp
        notice.cpp, .h
        

svn path=/trunk/boinc/; revision=20065
This commit is contained in:
Rom Walton 2010-01-04 17:43:18 +00:00
parent 3530f59d73
commit 56391da25a
5 changed files with 212 additions and 144 deletions

View File

@ -17,3 +17,14 @@ David 4 Jan 2010
cs_notice.cpp,h
lib/
notice.cpp
Rom 4 Jan 2010
- lib: fixup notice RPCs to make them manager compatible.
- lib: remove memset from notice constructor, bad things can happen
when you null out a std::string structure.
lib/
gui_rpc_client.h
gui_rpc_client_ops.cpp
notice.cpp, .h

View File

@ -438,6 +438,17 @@ public:
void clear();
};
class NOTICES {
public:
std::vector<NOTICE*> notices;
NOTICES();
~NOTICES();
void print();
void clear();
};
struct DISPLAY_INFO {
char window_station[256]; // windows
char desktop[256]; // windows
@ -635,6 +646,8 @@ public:
int get_proxy_settings(GR_PROXY_INFO&);
int get_messages(int seqno, MESSAGES&);
int get_message_count(int& seqno);
int get_notices(int seqno, NOTICES&);
int get_notices_public(int seqno, NOTICES&);
int file_transfer_op(FILE_TRANSFER&, const char*);
int result_op(RESULT&, const char*);
int get_host_info(HOST_INFO&);
@ -679,8 +692,6 @@ public:
int get_global_prefs_override_struct(GLOBAL_PREFS&, GLOBAL_PREFS_MASK&);
int set_global_prefs_override_struct(GLOBAL_PREFS&, GLOBAL_PREFS_MASK&);
int set_debts(std::vector<PROJECT>);
int get_notices(int, std::vector<NOTICE>&);
int get_notices_public(int, std::vector<NOTICE>&);
};
struct RPC {

View File

@ -851,6 +851,22 @@ void MESSAGES::clear() {
messages.clear();
}
NOTICES::NOTICES() {
clear();
}
NOTICES::~NOTICES() {
clear();
}
void NOTICES::clear() {
unsigned int i;
for (i=0; i<notices.size(); i++) {
delete notices[i];
}
notices.clear();
}
ACCT_MGR_INFO::ACCT_MGR_INFO() {
clear();
}
@ -2282,7 +2298,7 @@ int RPC_CLIENT::set_debts(vector<PROJECT> projects) {
return retval;
}
static int parse_notices(MIOFILE& fin, vector<NOTICE>& notices) {
static int parse_notices(MIOFILE& fin, NOTICES& notices) {
XML_PARSER xp(&fin);
char tag[256];
bool is_tag;
@ -2291,17 +2307,19 @@ static int parse_notices(MIOFILE& fin, vector<NOTICE>& notices) {
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) continue;
if (!strcmp(tag, "notice")) {
NOTICE notice;
retval = notice.parse(xp);
NOTICE* np = new NOTICE();
retval = np->parse(xp);
if (!retval) {
notices.push_back(notice);
notices.notices.push_back(np);
} else {
delete np;
}
}
}
return 0;
}
int RPC_CLIENT::get_notices(int seqno, vector<NOTICE>& notices) {
int RPC_CLIENT::get_notices(int seqno, NOTICES& notices) {
SET_LOCALE sl;
char buf[1024];
RPC rpc(this);
@ -2318,7 +2336,7 @@ int RPC_CLIENT::get_notices(int seqno, vector<NOTICE>& notices) {
return parse_notices(rpc.fin, notices);
}
int RPC_CLIENT::get_notices_public(int seqno, vector<NOTICE>& notices) {
int RPC_CLIENT::get_notices_public(int seqno, NOTICES& notices) {
SET_LOCALE sl;
char buf[1024];
RPC rpc(this);

View File

@ -1,80 +1,106 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// 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.
//
// BOINC 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
#include "boinc_win.h"
#endif
#include "error_numbers.h"
#include "notice.h"
// This is to parse our own XML.
// parse_rss() parses an RSS feed item.
//
int NOTICE::parse(XML_PARSER& xp) {
char tag[1024];
bool is_tag;
memset(this, 0, sizeof(*this));
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) continue;
if (!strcmp(tag, "/notice")) {
return 0;
}
if (xp.parse_int(tag, "seqno", seqno)) continue;
if (xp.parse_str(tag, "title", title, sizeof(title))) continue;
if (xp.parse_string(tag, "description", description)) continue;
if (xp.parse_double(tag, "create_time", create_time)) continue;
if (xp.parse_double(tag, "arrival_time", arrival_time)) continue;
if (xp.parse_bool(tag, "is_private", is_private)) continue;
if (xp.parse_str(tag, "category", category, sizeof(category))) continue;
if (xp.parse_str(tag, "link", link, sizeof(link))) continue;
}
return ERR_XML_PARSE;
}
void NOTICE::write(MIOFILE& f, bool for_gui) {
f.printf(
"<notice>\n"
" <title>%s</title>\n"
" <description>%s</description>\n"
" <create_time>%f</create_time>\n"
" <arrival_time>%f</arrival_time>\n"
" <is_private>%d</is_private>\n"
" <category>%s</category>\n"
" <link>%s</link>\n",
title,
description.c_str(),
create_time,
arrival_time,
is_private?1:0,
category,
link
);
if (!for_gui) {
f.printf(
" <guid>%s</guid>\n", guid
);
} else {
f.printf(
" <seqno>%d</seqno>\n", seqno
);
}
f.printf(
"</notice>\n"
);
}
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// 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.
//
// BOINC 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
#include "boinc_win.h"
#endif
#include "error_numbers.h"
#include "notice.h"
NOTICE::NOTICE() {
clear();
}
NOTICE::~NOTICE() {
clear();
}
// This is to parse our own XML.
// parse_rss() parses an RSS feed item.
//
int NOTICE::parse(XML_PARSER& xp) {
char tag[1024];
bool is_tag;
memset(this, 0, sizeof(*this));
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) continue;
if (!strcmp(tag, "/notice")) {
return 0;
}
if (xp.parse_int(tag, "seqno", seqno)) continue;
if (xp.parse_str(tag, "title", title, sizeof(title))) continue;
if (xp.parse_string(tag, "description", description)) continue;
if (xp.parse_double(tag, "create_time", create_time)) continue;
if (xp.parse_double(tag, "arrival_time", arrival_time)) continue;
if (xp.parse_bool(tag, "is_private", is_private)) continue;
if (xp.parse_str(tag, "category", category, sizeof(category))) continue;
if (xp.parse_str(tag, "link", link, sizeof(link))) continue;
}
return ERR_XML_PARSE;
}
void NOTICE::write(MIOFILE& f, bool for_gui) {
f.printf(
"<notice>\n"
" <title>%s</title>\n"
" <description>%s</description>\n"
" <create_time>%f</create_time>\n"
" <arrival_time>%f</arrival_time>\n"
" <is_private>%d</is_private>\n"
" <category>%s</category>\n"
" <link>%s</link>\n",
title,
description.c_str(),
create_time,
arrival_time,
is_private?1:0,
category,
link
);
if (!for_gui) {
f.printf(
" <guid>%s</guid>\n", guid
);
} else {
f.printf(
" <seqno>%d</seqno>\n", seqno
);
}
f.printf(
"</notice>\n"
);
}
void NOTICE::clear() {
seqno = 0;
strcpy(title, "");
description = "";
create_time = 0;
arrival_time = 0;
is_private = 0;
strcpy(category, "");
strcpy(guid, "");
strcpy(feed_url, "");
}

View File

@ -1,56 +1,58 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// 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.
//
// BOINC 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#ifndef __NOTICE_H__
#define __NOTICE_H__
#include <string>
#include "parse.h"
// represents a notice delivered from client to GUI
struct NOTICE {
int seqno;
char title[256];
std::string description;
double create_time;
double arrival_time; // when item arrived at client
bool is_private;
char category[64];
// assigned by RSS source. Reserved values:
// "client": generated by client
// "server": scheduler RPC message
char link[256];
// URL where original message can be seen, if any
char project_name[64];
// if notice is associated with a project
// the following fields used in client only (not reported to GUI)
char guid[256];
char feed_url[256];
// URL of RSS feed, or blank
NOTICE() {
memset(this, 0, sizeof(NOTICE));
}
int parse(XML_PARSER&);
int parse_rss(XML_PARSER&);
void write(MIOFILE&, bool for_gui);
};
#endif
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// 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.
//
// BOINC 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.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#ifndef __NOTICE_H__
#define __NOTICE_H__
#include <string>
#include "parse.h"
// represents a notice delivered from client to GUI
class NOTICE {
public:
int seqno;
char title[256];
std::string description;
double create_time;
double arrival_time; // when item arrived at client
bool is_private;
char category[64];
// assigned by RSS source. Reserved values:
// "client": generated by client
// "server": scheduler RPC message
char link[256];
// URL where original message can be seen, if any
char project_name[64];
// if notice is associated with a project
// the following fields used in client only (not reported to GUI)
char guid[256];
char feed_url[256];
// URL of RSS feed, or blank
NOTICE();
~NOTICE();
int parse(XML_PARSER&);
int parse_rss(XML_PARSER&);
void write(MIOFILE&, bool for_gui);
void clear();
};
#endif