diff --git a/checkin_notes b/checkin_notes index d97d1157c5..ccca4fb201 100644 --- a/checkin_notes +++ b/checkin_notes @@ -10303,3 +10303,16 @@ David 18 Dec 2009 client/ app_start.cpp + +David 18 Dec 2009 + - client and GUI RPC: add some plumbing for notices + + client/ + Makefile.am + cs_notice.cpp,h (new) + gui_rpc_server_ops.cpp + lib/ + Makefile.am + gui_rpc_client.h + gui_rpc_client_ops.cpp + notice.cpp,h (new) diff --git a/client/Makefile.am b/client/Makefile.am index 362498d967..d69fc663a1 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -49,6 +49,7 @@ boinc_client_SOURCES = \ cs_benchmark.cpp \ cs_cmdline.cpp \ cs_files.cpp \ + cs_notice.cpp \ cs_platforms.cpp \ cs_prefs.cpp \ cs_proxy.cpp \ diff --git a/client/cs_notice.cpp b/client/cs_notice.cpp new file mode 100644 index 0000000000..e957de6941 --- /dev/null +++ b/client/cs_notice.cpp @@ -0,0 +1,34 @@ +// 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 . + +#include "cs_notice.h" + +using std::deque; + +deque notices; + +void write_notices(int seqno, MIOFILE& fout, bool public_only) { + unsigned int i; + fout.printf("\n"); + for (i=0; i\n"); +} diff --git a/client/cs_notice.h b/client/cs_notice.h new file mode 100644 index 0000000000..b5e27d5587 --- /dev/null +++ b/client/cs_notice.h @@ -0,0 +1,38 @@ +// 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 . + +#include + +#include "miofile.h" +#include "notice.h" + +extern std::deque notices; + +extern void write_notices(int seqno, MIOFILE&, bool public_only); + +#if 0 +// RSS_FEED represents an RSS feed that the client +// polls periodically and caches on disk + +struct RSS_FEED { + char url[256]; + std::vector items; + + int fetch_start(); + int fetch_complete(); +}; +#endif diff --git a/client/gui_rpc_server_ops.cpp b/client/gui_rpc_server_ops.cpp index 31d9c58ae1..26ca349189 100644 --- a/client/gui_rpc_server_ops.cpp +++ b/client/gui_rpc_server_ops.cpp @@ -63,6 +63,7 @@ #include "client_msgs.h" #include "client_state.h" #include "cs_proxy.h" +#include "cs_notice.h" using std::string; using std::vector; @@ -1092,6 +1093,18 @@ static void handle_set_cc_config(char* buf, MIOFILE& fout) { ); } +static void handle_get_notices(char* buf, MIOFILE& fout) { + int seqno = 0; + parse_int(buf, "", seqno); + write_notices(seqno, fout, false); +} + +static void handle_get_notices_public(char* buf, MIOFILE& fout) { + int seqno = 0; + parse_int(buf, "", seqno); + write_notices(seqno, fout, true); +} + // Some of the RPCs have empty-element request messages. // We accept both and // @@ -1190,6 +1203,8 @@ int GUI_RPC_CONN::handle_rpc() { handle_get_cc_status(this, mf); } else if (match_req(request_msg, "get_all_projects_list")) { read_all_projects_list_file(mf); + } else if (match_req(request_msg, "get_notices_public")) { + handle_get_notices_public(request_msg, mf); // Operations that require authentication start here @@ -1269,10 +1284,13 @@ int GUI_RPC_CONN::handle_rpc() { gstate.request_work_fetch("Core client configuration"); } else if (match_req(request_msg, "set_debts")) { handle_set_debts(request_msg, mf); + } else if (match_req(request_msg, "get_notices")) { + handle_get_notices(request_msg, mf); } else { // RPCs after this point require authentication, - // and enable network communication for 5 minutes, overriding other factors. + // and enable network communication for 5 minutes, + // overriding other factors. // Things like attaching projects, etc. // diff --git a/lib/Makefile.am b/lib/Makefile.am index 65754e8408..e3952dc6b1 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -51,6 +51,7 @@ generic_sources = \ miofile.cpp \ msg_log.cpp \ network.cpp \ + notice.cpp \ parse.cpp \ prefs.cpp \ procinfo_unix.cpp \ @@ -110,6 +111,7 @@ pkginclude_HEADERS = \ miofile.h \ msg_log.h \ network.h \ + notice.h \ parse.h \ prefs.h \ proxy_info.h \ diff --git a/lib/gui_rpc_client.h b/lib/gui_rpc_client.h index 8dc10062a1..644d9ff451 100644 --- a/lib/gui_rpc_client.h +++ b/lib/gui_rpc_client.h @@ -33,6 +33,7 @@ #include "prefs.h" #include "hostinfo.h" #include "common_defs.h" +#include "notice.h" struct GUI_URL { std::string name; @@ -677,6 +678,8 @@ 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 d433c1c2e1..4317ee7dee 100644 --- a/lib/gui_rpc_client_ops.cpp +++ b/lib/gui_rpc_client_ops.cpp @@ -2280,5 +2280,54 @@ int RPC_CLIENT::set_debts(vector projects) { return retval; } +static int parse_notices(MIOFILE& fin, vector& notices) { + XML_PARSER xp(&fin); + char tag[256]; + bool is_tag; + int retval; + + while (!xp.get(tag, sizeof(tag), is_tag)) { + if (!is_tag) continue; + if (!strcmp(tag, "notice")) { + NOTICE notice; + retval = notice.parse(xp); + if (!retval) { + notices.push_back(notice); + } + } + } +} + +int RPC_CLIENT::get_notices(int seqno, vector& notices) { + SET_LOCALE sl; + char buf[1024]; + RPC rpc(this); + int retval; + + sprintf(buf, + "\n" + " %d\n" + "\n" + ); + retval = rpc.do_rpc(buf); + if (retval) return retval; + return parse_notices(rpc.fin, notices); +} + +int RPC_CLIENT::get_notices_public(int seqno, vector& notices) { + SET_LOCALE sl; + char buf[1024]; + RPC rpc(this); + int retval; + + sprintf(buf, + "\n" + " %d\n" + "\n" + ); + retval = rpc.do_rpc(buf); + if (retval) return retval; + return parse_notices(rpc.fin, notices); +} const char *BOINC_RCSID_90e8b8d168="$Id$"; diff --git a/lib/notice.cpp b/lib/notice.cpp new file mode 100644 index 0000000000..52bedf3e17 --- /dev/null +++ b/lib/notice.cpp @@ -0,0 +1,61 @@ +// 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 . + +#include "error_numbers.h" +#include "notice.h" + +int NOTICE::parse(XML_PARSER& xp) { + char tag[1024]; + bool is_tag; + + 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, "url", url, sizeof(url))) continue; + } + return ERR_XML_PARSE; +} + +void NOTICE::write(MIOFILE& f) { + f.printf( + "\n" + " %d\n" + " %s\n" + " %s\n" + " %f\n" + " %f\n" + " %d\n" + " %s\n" + " %s\n" + "\n", + seqno, + title, + description, + create_time, + arrival_time, + is_private?1:0, + category, + url + ); +} diff --git a/lib/notice.h b/lib/notice.h new file mode 100644 index 0000000000..6aea0a1cab --- /dev/null +++ b/lib/notice.h @@ -0,0 +1,39 @@ +// 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 . + +#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]; + char url[256]; + + // the following fields used in client only + char guid[256]; + + int parse(XML_PARSER&); + void write(MIOFILE&); +};