~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to lib/notice.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#if   defined(_WIN32) && !defined(__STDWX_H__)
 
19
#include "boinc_win.h"
 
20
#elif defined(_WIN32) && defined(__STDWX_H__)
 
21
#include "stdwx.h"
 
22
#endif
 
23
 
 
24
#include "error_numbers.h"
 
25
#include "notice.h"
 
26
 
 
27
 
 
28
NOTICE::NOTICE() {
 
29
    clear();
 
30
}
 
31
 
 
32
 
 
33
NOTICE::~NOTICE() {
 
34
    clear();
 
35
}
 
36
 
 
37
 
 
38
// This is to parse our own XML.
 
39
// parse_rss() parses an RSS feed item.
 
40
//
 
41
int NOTICE::parse(XML_PARSER& xp) {
 
42
    char tag[1024];
 
43
    bool is_tag;
 
44
 
 
45
    clear();
 
46
    while (!xp.get(tag, sizeof(tag), is_tag)) {
 
47
        if (!is_tag) continue;
 
48
        if (!strcmp(tag, "/notice")) {
 
49
            return 0;
 
50
        }
 
51
        if (xp.parse_int(tag, "seqno", seqno)) continue;
 
52
        if (xp.parse_str(tag, "title", title, sizeof(title))) continue;
 
53
        if (xp.parse_string(tag, "description", description)) {
 
54
            xml_unescape(description);   // 2nd pass
 
55
            continue;
 
56
        }
 
57
        if (xp.parse_double(tag, "create_time", create_time)) continue;
 
58
        if (xp.parse_double(tag, "arrival_time", arrival_time)) continue;
 
59
        if (xp.parse_bool(tag, "is_private", is_private)) continue;
 
60
        if (xp.parse_str(tag, "category", category, sizeof(category))) continue;
 
61
        if (xp.parse_str(tag, "link", link, sizeof(link))) continue;
 
62
        if (xp.parse_str(tag, "project_name", project_name, sizeof(project_name))) continue;
 
63
        if (xp.parse_str(tag, "guid", guid, sizeof(guid))) continue;
 
64
        if (xp.parse_str(tag, "feed_url", feed_url, sizeof(feed_url))) continue;
 
65
    }
 
66
    return ERR_XML_PARSE;
 
67
}
 
68
 
 
69
 
 
70
void NOTICE::write(MIOFILE& f, bool for_gui) {
 
71
    f.printf(
 
72
        "<notice>\n"
 
73
        "   <title>%s</title>\n"
 
74
        "   <description><![CDATA[\n%s\n]]></description>\n"
 
75
        "   <create_time>%f</create_time>\n"
 
76
        "   <arrival_time>%f</arrival_time>\n"
 
77
        "   <is_private>%d</is_private>\n"
 
78
        "   <project_name>%s</project_name>\n"
 
79
        "   <category>%s</category>\n"
 
80
        "   <link>%s</link>\n",
 
81
        title,
 
82
        description.c_str(),
 
83
        create_time,
 
84
        arrival_time,
 
85
        is_private?1:0,
 
86
        project_name,
 
87
        category,
 
88
        link
 
89
    );
 
90
    if (!for_gui) {
 
91
        f.printf(
 
92
            "   <guid>%s</guid>\n", guid
 
93
        );
 
94
    } else {
 
95
        f.printf(
 
96
            "   <seqno>%d</seqno>\n", seqno
 
97
        );
 
98
    }
 
99
    f.printf(
 
100
        "</notice>\n"
 
101
     );
 
102
}
 
103
 
 
104
 
 
105
void NOTICE::clear() {
 
106
    seqno = 0;
 
107
    strcpy(title, "");
 
108
    description = "";
 
109
    create_time = 0;
 
110
    arrival_time = 0;
 
111
    is_private = 0;
 
112
    strcpy(category, "");
 
113
    strcpy(link, "");
 
114
    strcpy(project_name, "");
 
115
    strcpy(guid, "");
 
116
    strcpy(feed_url, "");
 
117
}
 
118