1 #include "rss10parser.h"
2 
3 #include <cstring>
4 
5 #include "config.h"
6 #include "exception.h"
7 #include "feed.h"
8 #include "item.h"
9 #include "rsspp_uris.h"
10 #include "xmlutilities.h"
11 
12 #define RSS_1_0_NS "http://purl.org/rss/1.0/"
13 #define RDF_URI "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
14 
15 namespace rsspp {
16 
parse_feed(Feed & f,xmlNode * rootNode)17 void Rss10Parser::parse_feed(Feed& f, xmlNode* rootNode)
18 {
19 	if (!rootNode) {
20 		throw Exception(_("XML root node is NULL"));
21 	}
22 
23 	for (xmlNode* node = rootNode->children; node != nullptr;
24 		node = node->next) {
25 		if (node_is(node, "channel", RSS_1_0_NS)) {
26 			for (xmlNode* cnode = node->children; cnode != nullptr;
27 				cnode = cnode->next) {
28 				if (node_is(cnode, "title", RSS_1_0_NS)) {
29 					f.title = get_content(cnode);
30 					f.title_type = "text";
31 				} else if (node_is(cnode, "link", RSS_1_0_NS)) {
32 					f.link = get_content(cnode);
33 				} else if (node_is(cnode,
34 						"description",
35 						RSS_1_0_NS)) {
36 					f.description = get_content(cnode);
37 				} else if (node_is(cnode, "date", DC_URI)) {
38 					f.pubDate = w3cdtf_to_rfc822(
39 							get_content(cnode));
40 				} else if (node_is(cnode, "creator", DC_URI)) {
41 					f.dc_creator = get_content(cnode);
42 				}
43 			}
44 		} else if (node_is(node, "item", RSS_1_0_NS)) {
45 			Item it;
46 			it.guid = get_prop(node, "about", RDF_URI);
47 			for (xmlNode* itnode = node->children;
48 				itnode != nullptr;
49 				itnode = itnode->next) {
50 				if (node_is(itnode, "title", RSS_1_0_NS)) {
51 					it.title = get_content(itnode);
52 					it.title_type = "text";
53 				} else if (node_is(itnode,
54 						"link",
55 						RSS_1_0_NS)) {
56 					it.link = get_content(itnode);
57 				} else if (node_is(itnode,
58 						"description",
59 						RSS_1_0_NS)) {
60 					it.description = get_content(itnode);
61 					it.description_mime_type = "";
62 				} else if (node_is(itnode, "date", DC_URI)) {
63 					it.pubDate = w3cdtf_to_rfc822(
64 							get_content(itnode));
65 				} else if (node_is(itnode,
66 						"encoded",
67 						CONTENT_URI)) {
68 					it.content_encoded =
69 						get_content(itnode);
70 				} else if (node_is(itnode,
71 						"summary",
72 						ITUNES_URI)) {
73 					it.itunes_summary = get_content(itnode);
74 				} else if (node_is(itnode, "creator", DC_URI)) {
75 					it.author = get_content(itnode);
76 				}
77 			}
78 			f.items.push_back(it);
79 		}
80 	}
81 }
82 
83 } // namespace rsspp
84