1 // This file is part of BOINC. 2 // http://boinc.berkeley.edu 3 // Copyright (C) 2009 University of California 4 // 5 // BOINC is free software; you can redistribute it and/or modify it 6 // under the terms of the GNU Lesser General Public License 7 // as published by the Free Software Foundation, 8 // either version 3 of the License, or (at your option) any later version. 9 // 10 // BOINC is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 // See the GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with BOINC. If not, see <http://www.gnu.org/licenses/>. 17 18 #ifndef BOINC_CS_NOTICE_H 19 #define BOINC_CS_NOTICE_H 20 21 // Code related to "notices", which come from 22 // 1) RSS feeds specified by projects and account managers 23 // 2) Scheduler replies (high-priority messages) 24 // 3) the client (MSG_USER_ALERT messages) 25 // 26 // Classes: 27 // 28 // NOTICE represents a notice of any the above types. 29 // Attributes include an "arrival time"; for RSS items, this is the time it 30 // arrived at the client, not the create time. 31 // 32 // NOTICES represents the set of all current notices. 33 // Each notice has a unique seqno, which is a total ordering 34 // compatible with increasing arrival time. 35 // GUI RPC allow the enumerating of notices above a given seqno. 36 // Seqnos are not permanent. 37 // 38 // RSS_FEED represents an RSS feed. 39 // The client polls each feed periodically. 40 // 41 // The last successful reply from each feed is cached on disk. 42 // 43 // Two projects may request the same feed. 44 // So each PROJECT has its own list of feeds. 45 // There's also a merged list "rss_feeds" where seqno is stored. 46 // 47 // files: 48 // notices/feeds.xml feed list 49 // notices/feeds_PROJ_URL.xml list of project feeds 50 // notices/RSS_URL.xml result of last fetch for a feed 51 // notices/archive_RSS_URL.xml archive for a feed 52 53 #include <deque> 54 #include <vector> 55 56 #include "miofile.h" 57 58 #include "gui_http.h" 59 #include "client_types.h" 60 #include "gui_rpc_server.h" 61 62 #include "notice.h" 63 64 struct NOTICES { 65 std::deque<NOTICE> notices; 66 // stored newest (i.e. highest seqno) message first 67 void write(int seqno, GUI_RPC_CONN&, bool public_only); 68 bool append(NOTICE&); 69 void init(); 70 void init_rss(); 71 int read_archive_file(const char* file, struct RSS_FEED*); 72 void write_archive(struct RSS_FEED*); 73 bool remove_dups(NOTICE&); 74 void remove_notices(PROJECT*, int which); 75 void clear_keep(); 76 // prior to parsing an RSS feed, we mark all notices as "don't keep". 77 // We clear this flag if the notice is present in the feed. 78 void unkeep(const char* url); 79 // called after parsing an RSS feed, 80 // to remove notices that weren't in the feed. clearNOTICES81 void clear() { 82 notices.clear(); 83 } 84 }; 85 86 // args to remove_notices() 87 #define REMOVE_NETWORK_MSG 0 88 // "need network access" notice 89 #define REMOVE_SCHEDULER_MSG 1 90 // msgs from scheduler 91 #define REMOVE_NO_WORK_MSG 2 92 // msgs about no work due to settings 93 #define REMOVE_CONFIG_MSG 3 94 // notices about cc_config.xml 95 #define REMOVE_APP_INFO_MSG 4 96 // notices about project/app_info.xml 97 #define REMOVE_APP_CONFIG_MSG 5 98 // notices about project/app_config.xml 99 100 extern NOTICES notices; 101 102 struct RSS_FEED { 103 char url[256]; 104 char url_base[256]; 105 char project_name[256]; 106 double poll_interval; 107 double next_poll_time; 108 bool found; 109 // temp used in garbage collection 110 111 int fetch_start(); 112 int fetch_complete(); 113 114 void write(MIOFILE&); 115 int parse_desc(XML_PARSER&); 116 int parse_items(XML_PARSER&, int&); 117 void feed_file_name(char*, int); 118 void archive_file_name(char*, int); 119 int read_archive_file(); 120 void delete_files(); 121 }; 122 123 struct RSS_FEED_OP: public GUI_HTTP_OP { 124 int error_num; 125 RSS_FEED* rfp; 126 127 RSS_FEED_OP(); ~RSS_FEED_OPRSS_FEED_OP128 virtual ~RSS_FEED_OP(){} 129 virtual void handle_reply(int http_op_retval); 130 bool poll(); 131 }; 132 133 extern RSS_FEED_OP rss_feed_op; 134 135 struct RSS_FEEDS { 136 std::vector<RSS_FEED> feeds; 137 void init(); 138 void trigger_fetch(struct PROJ_AM*); 139 void update_feed_list(); 140 RSS_FEED* lookup_url(char*); 141 void update_proj_am(PROJ_AM*); 142 void write_feed_list(); clearRSS_FEEDS143 void clear() { 144 feeds.clear(); 145 } 146 }; 147 148 extern RSS_FEEDS rss_feeds; 149 150 int parse_rss_feed_descs(XML_PARSER&, std::vector<RSS_FEED>&); 151 void handle_sr_feeds(std::vector<RSS_FEED>&, struct PROJ_AM*); 152 // process the feeds in a scheduler reply 153 154 void delete_project_notice_files(PROJECT*); 155 156 #endif 157