From ac3adff1d7b42db1c8f969d2577bc7eab1180ed7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 6 Jan 2010 21:39:31 +0000 Subject: [PATCH] - client: notice fixes svn path=/trunk/boinc/; revision=20085 --- checkin_notes | 7 +++ client/client_state.cpp | 1 + client/cs_notice.cpp | 109 +++++++++++++++++++++++----------------- client/cs_notice.h | 4 +- 4 files changed, 74 insertions(+), 47 deletions(-) diff --git a/checkin_notes b/checkin_notes index 99883634bd..e4029c57ee 100644 --- a/checkin_notes +++ b/checkin_notes @@ -140,3 +140,10 @@ David 6 Jan 2010 client/ work_fetch.cpp + +David 6 Jan 2010 + - client: notice fixes + + client/ + client_state.cpp + cs_notice.cpp,h diff --git a/client/client_state.cpp b/client/client_state.cpp index 2b1deb7c97..6f58f0847f 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -463,6 +463,7 @@ int CLIENT_STATE::init() { auto_update.init(); http_ops->cleanup_temp_files(); + notices.init_rss(); initialized = true; return 0; diff --git a/client/cs_notice.cpp b/client/cs_notice.cpp index 6707dc71ec..b033f9b74a 100644 --- a/client/cs_notice.cpp +++ b/client/cs_notice.cpp @@ -149,7 +149,7 @@ void handle_sr_feeds(vector& feeds, PROJECT* p) { // if (feed_set_changed) { write_project_feed_list(p); - rss_feeds.update(); + rss_feeds.update_feed_list(); } } @@ -177,7 +177,6 @@ static int parse_rss_time(char* buf) { int n = sscanf(buf, "%s %d %s %d %d:%d:%d", day_name, &day_num, month_name, &year, &h, &m, &s ); - printf("n: %d\n", n); struct tm tm; tm.tm_sec = s; @@ -227,8 +226,17 @@ int NOTICE::parse_rss(XML_PARSER& xp) { ///////////// NOTICES //////////////// void NOTICES::init() { - // todo: read archive of client and server notices + read_archive_file(NOTICES_DIR"/archive.xml", NULL); + if (log_flags.notice_debug) { + msg_printf(0, MSG_INFO, "read %d BOINC notices", notices.size()); + } +} + +void NOTICES::init_rss() { rss_feeds.init(); + if (log_flags.notice_debug) { + msg_printf(0, MSG_INFO, "read %d total notices", notices.size()); + } // sort by decreasing arrival time, then assign seqnos // @@ -267,6 +275,55 @@ bool NOTICES::append_unique(NOTICE& n) { return true; } +// read and parse the contents of an archive file; +// insert items in NOTICES +// +int NOTICES::read_archive_file(char* path, char* feed_url) { + char tag[256]; + bool is_tag; + + FILE* f = fopen(path, "r"); + if (!f) { + if (log_flags.notice_debug) { + msg_printf(0, MSG_INFO, + "[notice_debug] no archive file %s", path + ); + } + return 0; + } + MIOFILE fin; + fin.init_file(f); + XML_PARSER xp(&fin); + while (!xp.get(tag, sizeof(tag), is_tag)) { + if (!is_tag) continue; + if (!strcmp(tag, "/notices")) { + fclose(f); + return 0; + } + if (!strcmp(tag, "notice")) { + NOTICE n; + int retval = n.parse(xp); + if (retval) { + if (log_flags.notice_debug) { + msg_printf(0, MSG_INFO, + "[notice_debug] archive item parse error: %d", retval + ); + } + } else { + if (feed_url) { + strcpy(n.feed_url, feed_url); + } + notices.push_front(n); + } + } + } + if (log_flags.notice_debug) { + msg_printf(0, MSG_INFO, "[notice_debug] archive parse error"); + } + fclose(f); + return ERR_XML_PARSE; +} + // get rid of old notices // void NOTICES::prune() { @@ -341,48 +398,8 @@ void RSS_FEED::archive_file_name(char* path) { // int RSS_FEED::read_archive_file() { char path[256]; - char tag[256]; - bool is_tag; - archive_file_name(path); - FILE* f = fopen(path, "r"); - if (!f) { - if (log_flags.notice_debug) { - msg_printf(0, MSG_INFO, - "[notice_debug] no archive file for %s", url - ); - } - return 0; - } - MIOFILE fin; - fin.init_file(f); - XML_PARSER xp(&fin); - while (!xp.get(tag, sizeof(tag), is_tag)) { - if (!is_tag) continue; - if (!strcmp(tag, "/notices")) { - fclose(f); - return 0; - } - if (!strcmp(tag, "notice")) { - NOTICE n; - int retval = n.parse(xp); - if (retval) { - if (log_flags.notice_debug) { - msg_printf(0, MSG_INFO, - "[notice_debug] archive item parse error: %d", retval - ); - } - } else { - strcpy(n.feed_url, url); - notices.append(n); - } - } - } - if (log_flags.notice_debug) { - msg_printf(0, MSG_INFO, "[notice_debug] archive parse error"); - } - fclose(f); - return ERR_XML_PARSE; + return notices.read_archive_file(path, url); } // parse a feed descriptor (in scheduler reply or feed list file) @@ -573,7 +590,7 @@ void RSS_FEEDS::init() { // normally the main list is union of the project lists. // if it's not, the following will fix // - update(); + update_feed_list(); for (i=0; i feeds; void init(); - void update(); + void update_feed_list(); RSS_FEED* lookup_url(char*); void write_feed_list(); };