From 56391da25a1b0c1471604dc5d760a458b8409286 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Mon, 4 Jan 2010 17:43:18 +0000 Subject: [PATCH] - 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 --- checkin_notes | 11 +++ lib/gui_rpc_client.h | 15 ++- lib/gui_rpc_client_ops.cpp | 30 ++++-- lib/notice.cpp | 186 +++++++++++++++++++++---------------- lib/notice.h | 114 ++++++++++++----------- 5 files changed, 212 insertions(+), 144 deletions(-) diff --git a/checkin_notes b/checkin_notes index c429a4e594..c3059d940a 100644 --- a/checkin_notes +++ b/checkin_notes @@ -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 + \ No newline at end of file diff --git a/lib/gui_rpc_client.h b/lib/gui_rpc_client.h index 49f73da7ea..a8dfd9b3b3 100644 --- a/lib/gui_rpc_client.h +++ b/lib/gui_rpc_client.h @@ -438,6 +438,17 @@ public: void clear(); }; +class NOTICES { +public: + std::vector 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); - int get_notices(int, std::vector&); - int get_notices_public(int, std::vector&); }; struct RPC { diff --git a/lib/gui_rpc_client_ops.cpp b/lib/gui_rpc_client_ops.cpp index 85aa616331..075263e6ee 100644 --- a/lib/gui_rpc_client_ops.cpp +++ b/lib/gui_rpc_client_ops.cpp @@ -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 projects) { return retval; } -static int parse_notices(MIOFILE& fin, vector& 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& 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& 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& notices) { return parse_notices(rpc.fin, notices); } -int RPC_CLIENT::get_notices_public(int seqno, vector& notices) { +int RPC_CLIENT::get_notices_public(int seqno, NOTICES& notices) { SET_LOCALE sl; char buf[1024]; RPC rpc(this); diff --git a/lib/notice.cpp b/lib/notice.cpp index f047048dd3..c2eed4a710 100644 --- a/lib/notice.cpp +++ b/lib/notice.cpp @@ -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 . - -#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( - "\n" - " %s\n" - " %s\n" - " %f\n" - " %f\n" - " %d\n" - " %s\n" - " %s\n", - title, - description.c_str(), - create_time, - arrival_time, - is_private?1:0, - category, - link - ); - if (!for_gui) { - f.printf( - " %s\n", guid - ); - } else { - f.printf( - " %d\n", seqno - ); - } - f.printf( - "\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 . + +#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( + "\n" + " %s\n" + " %s\n" + " %f\n" + " %f\n" + " %d\n" + " %s\n" + " %s\n", + title, + description.c_str(), + create_time, + arrival_time, + is_private?1:0, + category, + link + ); + if (!for_gui) { + f.printf( + " %s\n", guid + ); + } else { + f.printf( + " %d\n", seqno + ); + } + f.printf( + "\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, ""); +} + diff --git a/lib/notice.h b/lib/notice.h index 2fee8bd7fc..28975b8a39 100644 --- a/lib/notice.h +++ b/lib/notice.h @@ -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 . - -#ifndef __NOTICE_H__ -#define __NOTICE_H__ - -#include - -#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 . + +#ifndef __NOTICE_H__ +#define __NOTICE_H__ + +#include + +#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