Rename Channel => Feed and Item => Entry
This commit is contained in:
parent
f2f6f10496
commit
f9e6a53cb7
4
Makefile
4
Makefile
|
@ -29,8 +29,8 @@ APP_MIME_SIG = application/x-vnd.Pogger
|
||||||
# same name (source.c or source.cpp) are included from different directories.
|
# same name (source.c or source.cpp) are included from different directories.
|
||||||
# Also note that spaces in folder names do not work well with this Makefile.
|
# Also note that spaces in folder names do not work well with this Makefile.
|
||||||
SRCS = \
|
SRCS = \
|
||||||
src/Channel.cpp, \
|
src/Feed.cpp, \
|
||||||
src/Item.cpp, \
|
src/Entry.cpp, \
|
||||||
src/ProtocolListener.cpp, \
|
src/ProtocolListener.cpp, \
|
||||||
src/Config.cpp, \
|
src/Config.cpp, \
|
||||||
src/Util.cpp, \
|
src/Util.cpp, \
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
#include <tinyxml2.h>
|
|
||||||
#include "Util.h"
|
|
||||||
#include "Channel.h"
|
|
||||||
#include "Item.h"
|
|
||||||
#include "Config.h"
|
|
||||||
#include "parsing.h"
|
|
||||||
|
|
||||||
Channel::Channel ( BString path, BString outputPath )
|
|
||||||
{
|
|
||||||
title = BString("Untitled Feed");
|
|
||||||
description = BString("Nondescript, N/A.");
|
|
||||||
homePage = BString("");
|
|
||||||
xmlUrl = BString("");
|
|
||||||
filePath = path;
|
|
||||||
// lastDate = NULL;
|
|
||||||
topLevelSubject = "";
|
|
||||||
lastSubject = "";
|
|
||||||
outputDir = outputPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Channel::Parse ( Config* cfg )
|
|
||||||
{
|
|
||||||
items = BList();
|
|
||||||
Channel* chan = this;
|
|
||||||
feedParser(&chan, cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Channel::SetTitle ( const char* titleStr ) {
|
|
||||||
if ( titleStr != NULL ) title = BString( titleStr );
|
|
||||||
else return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool Channel::SetTitle ( tinyxml2::XMLElement* elem ) {
|
|
||||||
if ( elem != NULL ) return SetTitle( elem->GetText() );
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Channel::SetDesc ( const char* descStr ) {
|
|
||||||
if ( descStr != NULL ) description = BString( descStr );
|
|
||||||
else return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool Channel::SetDesc ( tinyxml2::XMLElement* elem ) {
|
|
||||||
if ( elem != NULL ) return SetDesc( elem->GetText() );
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Channel::SetHomePage ( const char* homepageStr ) {
|
|
||||||
if ( homepageStr != NULL ) homePage = BString( homepageStr );
|
|
||||||
else return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool Channel::SetHomePage ( tinyxml2::XMLElement* elem ) {
|
|
||||||
if ( elem != NULL ) return SetHomePage( elem->GetText() );
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Channel::SetLastDate ( const char* dateCStr ) {
|
|
||||||
if ( dateCStr == NULL )
|
|
||||||
return false;
|
|
||||||
BDateTime date = feedDateToBDate( dateCStr );
|
|
||||||
if ( date == NULL )
|
|
||||||
return false;
|
|
||||||
lastDate = date;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool Channel::SetLastDate ( tinyxml2::XMLElement* elem ) {
|
|
||||||
if ( elem != NULL ) return SetLastDate( elem->GetText() );
|
|
||||||
|
|
||||||
else return false;
|
|
||||||
}
|
|
|
@ -3,22 +3,20 @@
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
#include <StorageKit.h>
|
#include <StorageKit.h>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Item.h"
|
#include "Entry.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
|
||||||
Item::Item ( BString outputPath )
|
Entry::Entry ( BString outputPath )
|
||||||
{
|
{
|
||||||
title = BString("");
|
title = BString("");
|
||||||
description = BString("");
|
description = BString("");
|
||||||
homePage = BString("");
|
|
||||||
postUrl = BString("");
|
postUrl = BString("");
|
||||||
content = BString("");
|
content = BString("");
|
||||||
// pubDate = NULL;
|
|
||||||
outputDir = outputPath;
|
outputDir = outputPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Item::Filetize ( Config* cfg, bool onlyIfNew = false )
|
Entry::Filetize ( Config* cfg, bool onlyIfNew = false )
|
||||||
{
|
{
|
||||||
BDirectory* dir = new BDirectory( outputDir );
|
BDirectory* dir = new BDirectory( outputDir );
|
||||||
BFile* file = new BFile( title.String(), B_READ_WRITE );
|
BFile* file = new BFile( title.String(), B_READ_WRITE );
|
||||||
|
@ -26,13 +24,13 @@ Item::Filetize ( Config* cfg, bool onlyIfNew = false )
|
||||||
dir->CreateFile( title.String(), file );
|
dir->CreateFile( title.String(), file );
|
||||||
|
|
||||||
BString betype = cfg->mimetype;
|
BString betype = cfg->mimetype;
|
||||||
if ( pubDate != NULL ) {
|
if ( date != NULL ) {
|
||||||
int32 unixDate = (int32)pubDate.Time_t();
|
int32 unixDate = (int32)date.Time_t();
|
||||||
file->WriteAttr( "unixDate", B_INT32_TYPE, 0,
|
file->WriteAttr( "unixDate", B_INT32_TYPE, 0,
|
||||||
&unixDate, sizeof(int32) );
|
&unixDate, sizeof(int32) );
|
||||||
file->WriteAttr( "pubDate", B_STRING_TYPE, 0,
|
file->WriteAttr( "date", B_STRING_TYPE, 0,
|
||||||
dateTo3339String(pubDate).String(),
|
dateTo3339String(date).String(),
|
||||||
dateTo3339String(pubDate).CountChars() );
|
dateTo3339String(date).CountChars() );
|
||||||
}
|
}
|
||||||
|
|
||||||
file->WriteAttr( "META:title", B_STRING_TYPE, 0,
|
file->WriteAttr( "META:title", B_STRING_TYPE, 0,
|
||||||
|
@ -48,56 +46,56 @@ Item::Filetize ( Config* cfg, bool onlyIfNew = false )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::SetTitle ( const char* titleStr ) {
|
bool Entry::SetTitle ( const char* titleStr ) {
|
||||||
if ( titleStr != NULL ) title = BString( titleStr );
|
if ( titleStr != NULL ) title = BString( titleStr );
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool Item::SetTitle ( tinyxml2::XMLElement* elem ) {
|
bool Entry::SetTitle ( tinyxml2::XMLElement* elem ) {
|
||||||
if ( elem != NULL ) return SetTitle( elem->GetText() );
|
if ( elem != NULL ) return SetTitle( elem->GetText() );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::SetDesc ( const char* descStr ) {
|
bool Entry::SetDesc ( const char* descStr ) {
|
||||||
if ( descStr != NULL ) description = BString( descStr );
|
if ( descStr != NULL ) description = BString( descStr );
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool Item::SetDesc ( tinyxml2::XMLElement* elem ) {
|
bool Entry::SetDesc ( tinyxml2::XMLElement* elem ) {
|
||||||
if ( elem != NULL ) return SetDesc( elem->GetText() );
|
if ( elem != NULL ) return SetDesc( elem->GetText() );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::SetContent ( const char* contentStr ) {
|
bool Entry::SetContent ( const char* contentStr ) {
|
||||||
if ( contentStr != NULL ) content = BString( contentStr );
|
if ( contentStr != NULL ) content = BString( contentStr );
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool Item::SetContent ( tinyxml2::XMLElement* elem ) {
|
bool Entry::SetContent ( tinyxml2::XMLElement* elem ) {
|
||||||
if ( elem != NULL ) return SetContent( elem->GetText() );
|
if ( elem != NULL ) return SetContent( elem->GetText() );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::SetPostUrl ( const char* urlStr ) {
|
bool Entry::SetPostUrl ( const char* urlStr ) {
|
||||||
if ( urlStr != NULL ) postUrl = BString( urlStr );
|
if ( urlStr != NULL ) postUrl = BString( urlStr );
|
||||||
else return false;
|
else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool Item::SetPostUrl ( tinyxml2::XMLElement* elem ) {
|
bool Entry::SetPostUrl ( tinyxml2::XMLElement* elem ) {
|
||||||
if ( elem != NULL ) return SetPostUrl( elem->GetText() );
|
if ( elem != NULL ) return SetPostUrl( elem->GetText() );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::SetPubDate ( const char* dateStr ) {
|
bool Entry::SetDate ( const char* dateStr ) {
|
||||||
if ( dateStr == NULL )
|
if ( dateStr == NULL )
|
||||||
return false;
|
return false;
|
||||||
BDateTime date = feedDateToBDate( dateStr );
|
BDateTime newDate = feedDateToBDate( dateStr );
|
||||||
if ( date == NULL )
|
if ( newDate == NULL )
|
||||||
return false;
|
return false;
|
||||||
pubDate = date;
|
date = newDate;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool Item::SetPubDate ( tinyxml2::XMLElement* elem ) {
|
bool Entry::SetDate ( tinyxml2::XMLElement* elem ) {
|
||||||
if ( elem != NULL ) return SetPubDate( elem->GetText() );
|
if ( elem != NULL ) return SetDate( elem->GetText() );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
|
@ -1,23 +1,23 @@
|
||||||
#ifndef ITEM_H
|
#ifndef ENTRY_H
|
||||||
#define ITEM_H
|
#define ENTRY_H
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <DateTime.h>
|
#include <DateTime.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <Url.h>
|
#include <Url.h>
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
class Item {
|
class Entry {
|
||||||
public:
|
public:
|
||||||
BString title;
|
BString title;
|
||||||
BString description;
|
BString description;
|
||||||
BDateTime pubDate;
|
BDateTime date;
|
||||||
BString homePage;
|
|
||||||
BString postUrl;
|
BString postUrl;
|
||||||
BString content;
|
BString content;
|
||||||
BString outputDir;
|
BString outputDir;
|
||||||
|
|
||||||
Item ( BString );
|
Entry ( BString );
|
||||||
|
|
||||||
bool Filetize ( Config*, bool );
|
bool Filetize ( Config*, bool );
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ public:
|
||||||
bool SetContent ( tinyxml2::XMLElement* );
|
bool SetContent ( tinyxml2::XMLElement* );
|
||||||
bool SetPostUrl ( const char* );
|
bool SetPostUrl ( const char* );
|
||||||
bool SetPostUrl ( tinyxml2::XMLElement* );
|
bool SetPostUrl ( tinyxml2::XMLElement* );
|
||||||
bool SetPubDate ( const char* );
|
bool SetDate ( const char* );
|
||||||
bool SetPubDate ( tinyxml2::XMLElement* );
|
bool SetDate ( tinyxml2::XMLElement* );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
#include <tinyxml2.h>
|
||||||
|
#include "Entry.h"
|
||||||
|
#include "Config.h"
|
||||||
|
#include "parsing.h"
|
||||||
|
#include "Util.h"
|
||||||
|
#include "Feed.h"
|
||||||
|
|
||||||
|
Feed::Feed ( BString path, BString outputPath )
|
||||||
|
{
|
||||||
|
title = BString("Untitled Feed");
|
||||||
|
description = BString("Nondescript, N/A.");
|
||||||
|
homeUrl = BString("");
|
||||||
|
xmlUrl = BString("");
|
||||||
|
filePath = path;
|
||||||
|
// lastDate = NULL;
|
||||||
|
outputDir = outputPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Feed::Parse ( Config* cfg )
|
||||||
|
{
|
||||||
|
entries = BList();
|
||||||
|
Feed* feed = this;
|
||||||
|
feedParser(&feed, cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Feed::SetTitle ( const char* titleStr ) {
|
||||||
|
if ( titleStr != NULL ) title = BString( titleStr );
|
||||||
|
else return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool Feed::SetTitle ( tinyxml2::XMLElement* elem ) {
|
||||||
|
if ( elem != NULL ) return SetTitle( elem->GetText() );
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Feed::SetDesc ( const char* descStr ) {
|
||||||
|
if ( descStr != NULL ) description = BString( descStr );
|
||||||
|
else return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool Feed::SetDesc ( tinyxml2::XMLElement* elem ) {
|
||||||
|
if ( elem != NULL ) return SetDesc( elem->GetText() );
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Feed::SetHomeUrl ( const char* homepageStr ) {
|
||||||
|
if ( homepageStr != NULL ) homeUrl = BString( homepageStr );
|
||||||
|
else return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool Feed::SetHomeUrl ( tinyxml2::XMLElement* elem ) {
|
||||||
|
if ( elem != NULL ) return SetHomeUrl( elem->GetText() );
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Feed::SetDate ( const char* dateCStr ) {
|
||||||
|
if ( dateCStr == NULL )
|
||||||
|
return false;
|
||||||
|
BDateTime newDate = feedDateToBDate( dateCStr );
|
||||||
|
if ( newDate == NULL )
|
||||||
|
return false;
|
||||||
|
date = newDate;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool Feed::SetDate ( tinyxml2::XMLElement* elem ) {
|
||||||
|
if ( elem != NULL ) return SetDate( elem->GetText() );
|
||||||
|
|
||||||
|
else return false;
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef CHANNEL_H
|
#ifndef FEED_H
|
||||||
#define CHANNEL_H
|
#define FEED_H
|
||||||
|
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
#include <DateTime.h>
|
#include <DateTime.h>
|
||||||
|
@ -8,15 +8,15 @@
|
||||||
#include <Url.h>
|
#include <Url.h>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
|
||||||
class Channel {
|
class Feed {
|
||||||
public:
|
public:
|
||||||
char lang[3];
|
char lang[3];
|
||||||
BString title;
|
BString title;
|
||||||
BString description;
|
BString description;
|
||||||
BDateTime lastDate;
|
BDateTime date;
|
||||||
BString homePage;
|
BString homeUrl;
|
||||||
BString xmlUrl;
|
BString xmlUrl;
|
||||||
BList items;
|
BList entries;
|
||||||
|
|
||||||
BString topLevelSubject;
|
BString topLevelSubject;
|
||||||
BString lastSubject;
|
BString lastSubject;
|
||||||
|
@ -24,19 +24,18 @@ public:
|
||||||
BString outputDir;
|
BString outputDir;
|
||||||
|
|
||||||
|
|
||||||
Channel ( BString, BString );
|
Feed ( BString, BString );
|
||||||
// Channel ( BEntry );
|
|
||||||
// Channel ( BUrl );
|
|
||||||
void Parse ( Config* );
|
void Parse ( Config* );
|
||||||
|
|
||||||
bool SetTitle ( const char* );
|
bool SetTitle ( const char* );
|
||||||
bool SetTitle ( tinyxml2::XMLElement* );
|
bool SetTitle ( tinyxml2::XMLElement* );
|
||||||
bool SetDesc ( const char* );
|
bool SetDesc ( const char* );
|
||||||
bool SetDesc ( tinyxml2::XMLElement* );
|
bool SetDesc ( tinyxml2::XMLElement* );
|
||||||
bool SetLastDate ( const char* );
|
bool SetDate ( const char* );
|
||||||
bool SetLastDate ( tinyxml2::XMLElement* );
|
bool SetDate ( tinyxml2::XMLElement* );
|
||||||
bool SetHomePage ( const char* );
|
bool SetHomeUrl ( const char* );
|
||||||
bool SetHomePage ( tinyxml2::XMLElement* );
|
bool SetHomeUrl ( tinyxml2::XMLElement* );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,8 +1,8 @@
|
||||||
#include <StorageKit.h>
|
#include <StorageKit.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include "Channel.h"
|
#include "Feed.h"
|
||||||
#include "Item.h"
|
#include "Entry.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
@ -129,24 +129,24 @@ freeargInvocation ( int argc, char** argv, int optind, Config** cfgPtr )
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
processItem ( void* item )
|
processEntry ( void* entry )
|
||||||
{
|
{
|
||||||
Item* itemPtr = (Item*)item;
|
Entry* entryPtr = (Entry*)entry;
|
||||||
itemPtr->Filetize( main_cfg, false );
|
entryPtr->Filetize( main_cfg, false );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
processFeed ( void* feed )
|
processFeed ( void* feedArg )
|
||||||
{
|
{
|
||||||
BString* feedStr = (BString*)feed;
|
BString* feedStr = (BString*)feedArg;
|
||||||
|
|
||||||
Channel* chan = (Channel*)malloc( sizeof(Channel) );
|
Feed* feed = (Feed*)malloc( sizeof(feed) );
|
||||||
chan = new Channel(*(feedStr), main_cfg->outDir);
|
feed = new Feed(*(feedStr), main_cfg->outDir);
|
||||||
chan->Parse(main_cfg);
|
feed->Parse(main_cfg);
|
||||||
BList items = chan->items;
|
BList entries = feed->entries;
|
||||||
items.DoForEach(&processItem);
|
entries.DoForEach(&processEntry);
|
||||||
free(chan);
|
free(feed);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
143
src/parsing.cpp
143
src/parsing.cpp
|
@ -1,8 +1,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
#include "Channel.h"
|
#include "Feed.h"
|
||||||
#include "Item.h"
|
#include "Entry.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "parsing.h"
|
#include "parsing.h"
|
||||||
|
|
||||||
|
@ -10,82 +10,83 @@
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// PARSERS
|
// PARSERS
|
||||||
void
|
void
|
||||||
feedParser ( Channel** chanPtr, Config* cfg )
|
feedParser ( Feed** feedPtr, Config* cfg )
|
||||||
{
|
{
|
||||||
Channel* chan = *(chanPtr);
|
Feed* feed = *(feedPtr);
|
||||||
|
|
||||||
tinyxml2::XMLDocument xml;
|
tinyxml2::XMLDocument xml;
|
||||||
xml.LoadFile( chan->filePath.String() );
|
xml.LoadFile( feed->filePath.String() );
|
||||||
|
|
||||||
if ( xml.FirstChildElement("rss") )
|
if ( xml.FirstChildElement("rss") )
|
||||||
rssParser( chanPtr, cfg, &xml );
|
rssParser( feedPtr, cfg, &xml );
|
||||||
else if ( xml.FirstChildElement("feed") )
|
else if ( xml.FirstChildElement("feed") )
|
||||||
atomParser( chanPtr, cfg, &xml );
|
atomParser( feedPtr, cfg, &xml );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
rssParser ( Channel** chanPtr, Config* cfg, tinyxml2::XMLDocument* xml )
|
rssParser ( Feed** feedPtr, Config* cfg, tinyxml2::XMLDocument* xml )
|
||||||
{
|
{
|
||||||
Channel* chan = *(chanPtr);
|
Feed* chan = *(feedPtr);
|
||||||
|
|
||||||
tinyxml2::XMLElement* xchan = xml->FirstChildElement("rss")->FirstChildElement("channel");
|
tinyxml2::XMLElement* xchan = xml->FirstChildElement("rss")->FirstChildElement("channel");
|
||||||
|
|
||||||
rssRootParse( chanPtr, cfg, xchan );
|
rssRootParse( feedPtr, cfg, xchan );
|
||||||
rssParseItems( chanPtr, cfg, xchan );
|
rssParseEntries( feedPtr, cfg, xchan );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rssRootParse( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xchan )
|
rssRootParse( Feed** feedPtr, Config* cfg, tinyxml2::XMLElement* xchan )
|
||||||
{
|
{
|
||||||
Channel* chan = *(chanPtr);
|
Feed* feed = *(feedPtr);
|
||||||
|
|
||||||
chan->SetTitle( xchan->FirstChildElement("title") );
|
feed->SetTitle ( xchan->FirstChildElement("title") );
|
||||||
chan->SetDesc( xchan->FirstChildElement("description") );
|
feed->SetDesc ( xchan->FirstChildElement("description") );
|
||||||
chan->SetHomePage( xchan->FirstChildElement("link") );
|
feed->SetHomeUrl ( xchan->FirstChildElement("link") );
|
||||||
chan->SetLastDate( xchan->FirstChildElement("lastBuildDate") );
|
feed->SetDate ( xchan->FirstChildElement("lastBuildDate") );
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( cfg->verbose )
|
||||||
printf("Channel '%s' at '%s':\n", chan->title.String(), chan->homePage.String());
|
printf("Channel '%s' at '%s':\n", feed->title.String(), feed->homeUrl.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rssItemParse ( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xitem )
|
rssEntryParse ( Feed** feedPtr, Config* cfg, tinyxml2::XMLElement* xitem )
|
||||||
{
|
{
|
||||||
Channel* chan = *(chanPtr);
|
Feed* feed = *(feedPtr);
|
||||||
|
|
||||||
Item* newItem = (Item*)malloc( sizeof(Item) );
|
Entry* newEntry = (Entry*)malloc( sizeof(Entry) );
|
||||||
newItem = new Item( chan->outputDir );
|
newEntry = new Entry( feed->outputDir );
|
||||||
|
|
||||||
newItem->SetTitle( xitem->FirstChildElement("title") );
|
newEntry->SetTitle ( xitem->FirstChildElement("title") );
|
||||||
newItem->SetDesc( xitem->FirstChildElement("description") );
|
newEntry->SetDesc ( xitem->FirstChildElement("description") );
|
||||||
newItem->SetPubDate( xitem->FirstChildElement("pubDate") );
|
newEntry->SetDate ( xitem->FirstChildElement("pubDate") );
|
||||||
newItem->SetContent( xitem->FirstChildElement("content:encoded") );
|
newEntry->SetPostUrl ( xitem->FirstChildElement("link") );
|
||||||
|
newEntry->SetContent ( xitem->FirstChildElement("content:encoded") );
|
||||||
|
|
||||||
if (cfg->verbose )
|
if (cfg->verbose )
|
||||||
printf("\t%s\n", newItem->title.String());
|
printf("\t%s\n", newEntry->title.String());
|
||||||
|
|
||||||
if ( withinDateRange( cfg->minDate, newItem->pubDate, cfg->maxDate ) )
|
if ( withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) )
|
||||||
chan->items.AddItem( newItem );
|
feed->entries.AddItem( newEntry );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rssParseItems ( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xchan )
|
rssParseEntries ( Feed** feedPtr, Config* cfg, tinyxml2::XMLElement* xchan )
|
||||||
{
|
{
|
||||||
Channel* chan = *(chanPtr);
|
Feed* feed = *(feedPtr);
|
||||||
tinyxml2::XMLElement* xitem;
|
tinyxml2::XMLElement* xitem;
|
||||||
|
|
||||||
xitem = xchan->FirstChildElement("item");
|
xitem = xchan->FirstChildElement("item");
|
||||||
|
|
||||||
int itemCount = xmlCountSiblings( xitem, "item" );
|
int entryCount = xmlCountSiblings( xitem, "item" );
|
||||||
chan->items = BList(itemCount);
|
feed->entries = BList(entryCount);
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( cfg->verbose )
|
||||||
printf("\t-%i items-\n", itemCount);
|
printf("\t-%i entries-\n", entryCount);
|
||||||
|
|
||||||
while ( xitem ) {
|
while ( xitem ) {
|
||||||
rssItemParse( chanPtr, cfg, xitem );
|
rssEntryParse( feedPtr, cfg, xitem );
|
||||||
xitem = xitem->NextSiblingElement("item");
|
xitem = xitem->NextSiblingElement("item");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,20 +94,20 @@ rssParseItems ( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xchan )
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
atomParser ( Channel** chanPtr, Config* cfg, tinyxml2::XMLDocument* xml )
|
atomParser ( Feed** feedPtr, Config* cfg, tinyxml2::XMLDocument* xml )
|
||||||
{
|
{
|
||||||
Channel* chan = *(chanPtr);
|
Feed* feed = *(feedPtr);
|
||||||
|
|
||||||
tinyxml2::XMLElement* xfeed = xml->FirstChildElement("feed");
|
tinyxml2::XMLElement* xfeed = xml->FirstChildElement("feed");
|
||||||
|
|
||||||
atomRootParse( chanPtr, cfg, xfeed );
|
atomRootParse( feedPtr, cfg, xfeed );
|
||||||
atomParseEntries( chanPtr, cfg, xfeed );
|
atomParseEntries( feedPtr, cfg, xfeed );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
atomRootParse( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xfeed )
|
atomRootParse( Feed** feedPtr, Config* cfg, tinyxml2::XMLElement* xfeed )
|
||||||
{
|
{
|
||||||
Channel* chan = *(chanPtr);
|
Feed* feed = *(feedPtr);
|
||||||
|
|
||||||
tinyxml2::XMLElement* xauthor = xfeed->FirstChildElement("author");
|
tinyxml2::XMLElement* xauthor = xfeed->FirstChildElement("author");
|
||||||
tinyxml2::XMLElement* xentry = xfeed->FirstChildElement("entry");
|
tinyxml2::XMLElement* xentry = xfeed->FirstChildElement("entry");
|
||||||
|
@ -115,72 +116,72 @@ atomRootParse( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xfeed )
|
||||||
|
|
||||||
bool set = false;
|
bool set = false;
|
||||||
|
|
||||||
chan->SetTitle( xfeed->FirstChildElement("title") );
|
feed->SetTitle( xfeed->FirstChildElement("title") );
|
||||||
chan->SetDesc( xfeed->FirstChildElement("description") );
|
feed->SetDesc( xfeed->FirstChildElement("description") );
|
||||||
|
|
||||||
set = chan->SetLastDate( xfeed->FirstChildElement("updated") );
|
set = feed->SetDate( xfeed->FirstChildElement("updated") );
|
||||||
if ( !set ) set = chan->SetLastDate( xfeed->FirstChildElement("published") );
|
if ( !set ) set = feed->SetDate( xfeed->FirstChildElement("published") );
|
||||||
if ( !set && xentry ) set = chan->SetLastDate( xentry->FirstChildElement("updated") );
|
if ( !set && xentry ) set = feed->SetDate( xentry->FirstChildElement("updated") );
|
||||||
if ( !set && xentry ) set = chan->SetLastDate( xentry->FirstChildElement("published") );
|
if ( !set && xentry ) set = feed->SetDate( xentry->FirstChildElement("published") );
|
||||||
|
|
||||||
set = chan->SetHomePage( xlink->Attribute( "href" ) );
|
set = feed->SetHomeUrl( xlink->Attribute( "href" ) );
|
||||||
if ( !set && xauthor ) set = chan->SetHomePage( xauthor->FirstChildElement("uri") );
|
if ( !set && xauthor ) set = feed->SetHomeUrl( xauthor->FirstChildElement("uri") );
|
||||||
if ( !set && xauthlink ) set = chan->SetHomePage( xauthlink->Attribute( "href" ) );
|
if ( !set && xauthlink ) set = feed->SetHomeUrl( xauthlink->Attribute( "href" ) );
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( cfg->verbose )
|
||||||
printf("Channel '%s' at '%s':\n", chan->title.String(), chan->homePage.String());
|
printf("Channel '%s' at '%s':\n", feed->title.String(), feed->homeUrl.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
atomEntryParse ( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xentry )
|
atomEntryParse ( Feed** feedPtr, Config* cfg, tinyxml2::XMLElement* xentry )
|
||||||
{
|
{
|
||||||
Channel* chan = *(chanPtr);
|
Feed* feed = *(feedPtr);
|
||||||
Item* newItem = (Item*)malloc( sizeof(Item) );
|
Entry* newEntry= (Entry*)malloc( sizeof(Entry) );
|
||||||
newItem = new Item( chan->outputDir );
|
newEntry = new Entry( feed->outputDir );
|
||||||
|
|
||||||
tinyxml2::XMLElement* xcontent = xentry->FirstChildElement("content");
|
tinyxml2::XMLElement* xcontent = xentry->FirstChildElement("content");
|
||||||
tinyxml2::XMLElement* xmedia = xentry->FirstChildElement("media:group");
|
tinyxml2::XMLElement* xmedia = xentry->FirstChildElement("media:group");
|
||||||
tinyxml2::XMLPrinter xprinter;
|
tinyxml2::XMLPrinter xprinter;
|
||||||
|
|
||||||
newItem->SetTitle( xentry->FirstChildElement("title") );
|
newEntry->SetTitle( xentry->FirstChildElement("title") );
|
||||||
newItem->SetPostUrl( xentry->FirstChildElement("link")->Attribute("href") );
|
newEntry->SetPostUrl( xentry->FirstChildElement("link")->Attribute("href") );
|
||||||
|
|
||||||
bool set = false;
|
bool set = false;
|
||||||
set = newItem->SetDesc( xentry->FirstChildElement("summary") );
|
set = newEntry->SetDesc( xentry->FirstChildElement("summary") );
|
||||||
if ( !set ) set = newItem->SetDesc( xentry->FirstChildElement("description"));
|
if ( !set ) set = newEntry->SetDesc( xentry->FirstChildElement("description"));
|
||||||
if ( !set && xmedia ) set = newItem->SetDesc( xmedia->FirstChildElement("media:description"));
|
if ( !set && xmedia ) set = newEntry->SetDesc( xmedia->FirstChildElement("media:description"));
|
||||||
|
|
||||||
set = newItem->SetPubDate( xentry->FirstChildElement("updated") );
|
set = newEntry->SetDate( xentry->FirstChildElement("updated") );
|
||||||
if ( !set ) set = newItem->SetPubDate( xentry->FirstChildElement("published") );
|
if ( !set ) set = newEntry->SetDate( xentry->FirstChildElement("published") );
|
||||||
|
|
||||||
if ( xcontent ) {
|
if ( xcontent ) {
|
||||||
xcontent->Accept( &xprinter );
|
xcontent->Accept( &xprinter );
|
||||||
newItem->SetContent( xprinter.CStr() );
|
newEntry->SetContent( xprinter.CStr() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( cfg->verbose )
|
||||||
printf("\t%s\n", newItem->title.String());
|
printf("\t%s\n", newEntry->title.String());
|
||||||
|
|
||||||
if ( withinDateRange( cfg->minDate, newItem->pubDate, cfg->maxDate ) )
|
if ( withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) )
|
||||||
chan->items.AddItem( newItem );
|
feed->entries.AddItem( newEntry );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
atomParseEntries ( Channel** chanPtr, Config* cfg, tinyxml2::XMLElement* xfeed )
|
atomParseEntries ( Feed** feedPtr, Config* cfg, tinyxml2::XMLElement* xfeed )
|
||||||
{
|
{
|
||||||
Channel* chan = *(chanPtr);
|
Feed* feed = *(feedPtr);
|
||||||
tinyxml2::XMLElement* xentry;
|
tinyxml2::XMLElement* xentry;
|
||||||
|
|
||||||
xentry = xfeed->FirstChildElement("entry");
|
xentry = xfeed->FirstChildElement("entry");
|
||||||
|
|
||||||
int entryCount = xmlCountSiblings( xentry, "entry" );
|
int entryCount = xmlCountSiblings( xentry, "entry" );
|
||||||
chan->items = BList(entryCount);
|
feed->entries = BList(entryCount);
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( cfg->verbose )
|
||||||
printf("\t-%i items-\n", entryCount);
|
printf("\t-%i entries-\n", entryCount);
|
||||||
|
|
||||||
while ( xentry ) {
|
while ( xentry ) {
|
||||||
atomEntryParse( chanPtr, cfg, xentry );
|
atomEntryParse( feedPtr, cfg, xentry );
|
||||||
xentry = xentry->NextSiblingElement("entry");
|
xentry = xentry->NextSiblingElement("entry");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,17 @@
|
||||||
|
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Channel.h"
|
#include "Feed.h"
|
||||||
|
|
||||||
void feedParser ( Channel**, Config* );
|
void feedParser ( Feed**, Config* );
|
||||||
void rssParser ( Channel**, Config*, tinyxml2::XMLDocument* );
|
void rssParser ( Feed**, Config*, tinyxml2::XMLDocument* );
|
||||||
void rssRootParse ( Channel**, Config*, tinyxml2::XMLElement* );
|
void rssRootParse ( Feed**, Config*, tinyxml2::XMLElement* );
|
||||||
void rssItemParse ( Channel**, Config*, tinyxml2::XMLElement* );
|
void rssEntryParse ( Feed**, Config*, tinyxml2::XMLElement* );
|
||||||
void rssParseItems ( Channel**, Config*, tinyxml2::XMLElement* );
|
void rssParseEntries ( Feed**, Config*, tinyxml2::XMLElement* );
|
||||||
void atomParser ( Channel**, Config*, tinyxml2::XMLDocument* );
|
void atomParser ( Feed**, Config*, tinyxml2::XMLDocument* );
|
||||||
void atomRootParse ( Channel** chanPtr, Config*, tinyxml2::XMLElement* );
|
void atomRootParse ( Feed**, Config*, tinyxml2::XMLElement* );
|
||||||
void atomEntryParse ( Channel**, Config*, tinyxml2::XMLElement* );
|
void atomEntryParse ( Feed**, Config*, tinyxml2::XMLElement* );
|
||||||
void atomParseEntries ( Channel**, Config*, tinyxml2::XMLElement* );
|
void atomParseEntries ( Feed**, Config*, tinyxml2::XMLElement* );
|
||||||
int xmlCountSiblings ( tinyxml2::XMLElement*, const char* );
|
int xmlCountSiblings ( tinyxml2::XMLElement*, const char* );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Ŝarĝante…
Reference in New Issue