Move from global 'main_cfg' to be_app->cfg
This commit is contained in:
parent
d6975dbc98
commit
093c90aed2
14
src/App.cpp
14
src/App.cpp
|
@ -20,8 +20,8 @@ main ( int argc, char** argv )
|
||||||
usageMsg.ReplaceAll("%app%", "Pogger");
|
usageMsg.ReplaceAll("%app%", "Pogger");
|
||||||
feedMimeType();
|
feedMimeType();
|
||||||
|
|
||||||
main_cfg = new Config;
|
app->cfg = new Config;
|
||||||
main_cfg->Load();
|
app->cfg->Load();
|
||||||
|
|
||||||
|
|
||||||
if ( argc == 1 )
|
if ( argc == 1 )
|
||||||
|
@ -30,8 +30,8 @@ main ( int argc, char** argv )
|
||||||
cliStart( argc, argv );
|
cliStart( argc, argv );
|
||||||
|
|
||||||
|
|
||||||
if ( main_cfg->will_save == true )
|
if ( app->cfg->will_save == true )
|
||||||
main_cfg->Save();
|
app->cfg->Save();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@ main ( int argc, char** argv )
|
||||||
void
|
void
|
||||||
cliStart ( int argc, char** argv )
|
cliStart ( int argc, char** argv )
|
||||||
{
|
{
|
||||||
invocation( argc, argv, &main_cfg );
|
invocation( argc, argv );
|
||||||
main_cfg->targetFeeds.DoForEach( &processFeed );
|
((App*)be_app)->cfg->targetFeeds.DoForEach( &processFeed );
|
||||||
}
|
}
|
||||||
|
|
||||||
App::App ( )
|
App::App ( )
|
||||||
|
@ -55,8 +55,6 @@ App::App ( )
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
Config* main_cfg;
|
|
||||||
const char* configPath = "/boot/home/config/settings/Pogger/";
|
const char* configPath = "/boot/home/config/settings/Pogger/";
|
||||||
BString usageMsg =
|
BString usageMsg =
|
||||||
"Usage: %app% [-hvDus] [-tT datetime] [-cCO path] \n"
|
"Usage: %app% [-hvDus] [-tT datetime] [-cCO path] \n"
|
||||||
|
|
|
@ -3,12 +3,14 @@
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
|
|
||||||
class App : public BApplication
|
class App : public BApplication
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
App(void);
|
App(void);
|
||||||
|
Config* cfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -18,8 +20,6 @@ void cliStart ( int, char** );
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
extern Config* main_cfg;
|
|
||||||
|
|
||||||
extern const char* configPath;
|
extern const char* configPath;
|
||||||
|
|
||||||
extern BString usageMsg;
|
extern BString usageMsg;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
#include "Entry.h"
|
#include "Entry.h"
|
||||||
|
#include "App.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "AtomFeed.h"
|
#include "AtomFeed.h"
|
||||||
|
@ -11,30 +12,27 @@ AtomFeed::AtomFeed ( )
|
||||||
homeUrl = BString("");
|
homeUrl = BString("");
|
||||||
xmlUrl = BString("");
|
xmlUrl = BString("");
|
||||||
filePath = BString("");
|
filePath = BString("");
|
||||||
|
outputDir = ((App*)be_app)->cfg->outDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
AtomFeed::AtomFeed ( Feed* feed ) : AtomFeed::AtomFeed()
|
AtomFeed::AtomFeed ( Feed* feed ) : AtomFeed::AtomFeed()
|
||||||
{ filePath = feed->filePath; }
|
{ filePath = feed->filePath; }
|
||||||
AtomFeed::AtomFeed ( Feed* feed, Config* cfg ) : AtomFeed::AtomFeed( feed )
|
|
||||||
{ outputDir = cfg->outDir; }
|
|
||||||
AtomFeed::AtomFeed ( Config* cfg ) : AtomFeed::AtomFeed( )
|
|
||||||
{ outputDir = cfg->outDir; }
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
AtomFeed::Parse ( Config* cfg )
|
AtomFeed::Parse ( )
|
||||||
{
|
{
|
||||||
entries = BList();
|
entries = BList();
|
||||||
tinyxml2::XMLDocument xml;
|
tinyxml2::XMLDocument xml;
|
||||||
xml.LoadFile( filePath.String() );
|
xml.LoadFile( filePath.String() );
|
||||||
|
|
||||||
Feed::Parse( cfg );
|
Feed::Parse();
|
||||||
|
|
||||||
tinyxml2::XMLElement* xfeed = xml.FirstChildElement("feed");
|
tinyxml2::XMLElement* xfeed = xml.FirstChildElement("feed");
|
||||||
|
|
||||||
RootParse( cfg, xfeed );
|
RootParse( xfeed );
|
||||||
ParseEntries( cfg, xfeed );
|
ParseEntries( xfeed );
|
||||||
|
|
||||||
BFile* feedFile = new BFile( filePath.String(), B_READ_WRITE );
|
BFile* feedFile = new BFile( filePath.String(), B_READ_WRITE );
|
||||||
time_t tt_lastDate = lastDate.Time_t();
|
time_t tt_lastDate = lastDate.Time_t();
|
||||||
|
@ -42,7 +40,7 @@ AtomFeed::Parse ( Config* cfg )
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AtomFeed::RootParse( Config* cfg, tinyxml2::XMLElement* xfeed )
|
AtomFeed::RootParse( tinyxml2::XMLElement* xfeed )
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement* xauthor = xfeed->FirstChildElement("author");
|
tinyxml2::XMLElement* xauthor = xfeed->FirstChildElement("author");
|
||||||
tinyxml2::XMLElement* xentry = xfeed->FirstChildElement("entry");
|
tinyxml2::XMLElement* xentry = xfeed->FirstChildElement("entry");
|
||||||
|
@ -63,12 +61,12 @@ AtomFeed::RootParse( Config* cfg, tinyxml2::XMLElement* xfeed )
|
||||||
if ( !set && xauthor ) set = SetHomeUrl( xauthor->FirstChildElement("uri") );
|
if ( !set && xauthor ) set = SetHomeUrl( xauthor->FirstChildElement("uri") );
|
||||||
if ( !set && xauthlink ) set = SetHomeUrl( xauthlink->Attribute( "href" ) );
|
if ( !set && xauthlink ) set = SetHomeUrl( xauthlink->Attribute( "href" ) );
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( ((App*)be_app)->cfg->verbose )
|
||||||
printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String());
|
printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AtomFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xentry )
|
AtomFeed::EntryParse ( tinyxml2::XMLElement* xentry )
|
||||||
{
|
{
|
||||||
Entry* newEntry= (Entry*)malloc( sizeof(Entry) );
|
Entry* newEntry= (Entry*)malloc( sizeof(Entry) );
|
||||||
newEntry = new Entry( outputDir );
|
newEntry = new Entry( outputDir );
|
||||||
|
@ -97,11 +95,11 @@ AtomFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xentry )
|
||||||
newEntry->SetContent( xprinter.CStr() );
|
newEntry->SetContent( xprinter.CStr() );
|
||||||
}
|
}
|
||||||
|
|
||||||
AddEntry( cfg, newEntry );
|
AddEntry( newEntry );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AtomFeed::ParseEntries ( Config* cfg, tinyxml2::XMLElement* xfeed )
|
AtomFeed::ParseEntries ( tinyxml2::XMLElement* xfeed )
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement* xentry;
|
tinyxml2::XMLElement* xentry;
|
||||||
|
|
||||||
|
@ -110,11 +108,11 @@ AtomFeed::ParseEntries ( Config* cfg, tinyxml2::XMLElement* xfeed )
|
||||||
int entryCount = xmlCountSiblings( xentry, "entry" );
|
int entryCount = xmlCountSiblings( xentry, "entry" );
|
||||||
entries = BList(entryCount);
|
entries = BList(entryCount);
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( ((App*)be_app)->cfg->verbose )
|
||||||
printf("\t-%i entries-\n", entryCount);
|
printf("\t-%i entries-\n", entryCount);
|
||||||
|
|
||||||
while ( xentry ) {
|
while ( xentry ) {
|
||||||
EntryParse( cfg, xentry );
|
EntryParse( xentry );
|
||||||
xentry = xentry->NextSiblingElement("entry");
|
xentry = xentry->NextSiblingElement("entry");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,12 @@
|
||||||
class AtomFeed: public Feed {
|
class AtomFeed: public Feed {
|
||||||
public:
|
public:
|
||||||
AtomFeed ( );
|
AtomFeed ( );
|
||||||
AtomFeed ( Feed*, Config* );
|
|
||||||
AtomFeed ( Feed* );
|
AtomFeed ( Feed* );
|
||||||
AtomFeed ( Config* );
|
|
||||||
|
|
||||||
void Parse ( Config* );
|
void Parse ( );
|
||||||
void RootParse ( Config*, tinyxml2::XMLElement* );
|
void RootParse ( tinyxml2::XMLElement* );
|
||||||
void EntryParse ( Config*, tinyxml2::XMLElement* );
|
void EntryParse ( tinyxml2::XMLElement* );
|
||||||
void ParseEntries ( Config*, tinyxml2::XMLElement* );
|
void ParseEntries ( tinyxml2::XMLElement* );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,7 +17,7 @@ Entry::Entry ( BString outputPath )
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Entry::Filetize ( Config* cfg, bool onlyIfNew = false )
|
Entry::Filetize ( 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 );
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef ENTRY_H
|
#ifndef ENTRY_H
|
||||||
#define ENTRY_H
|
#define ENTRY_H
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <DateTime.h>
|
#include <DateTime.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
@ -20,7 +19,7 @@ public:
|
||||||
|
|
||||||
Entry ( BString );
|
Entry ( BString );
|
||||||
|
|
||||||
bool Filetize ( Config*, bool );
|
bool Filetize ( bool );
|
||||||
|
|
||||||
bool SetTitle ( const char* );
|
bool SetTitle ( const char* );
|
||||||
bool SetTitle ( tinyxml2::XMLElement* );
|
bool SetTitle ( tinyxml2::XMLElement* );
|
||||||
|
@ -35,6 +34,4 @@ public:
|
||||||
bool SetDate ( tinyxml2::XMLElement* );
|
bool SetDate ( tinyxml2::XMLElement* );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
22
src/Feed.cpp
22
src/Feed.cpp
|
@ -1,17 +1,18 @@
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
|
#include "App.h"
|
||||||
#include "Entry.h"
|
#include "Entry.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "Feed.h"
|
#include "Feed.h"
|
||||||
|
|
||||||
Feed::Feed ( BString path, Config* cfg )
|
Feed::Feed ( BString path )
|
||||||
{
|
{
|
||||||
title = BString( "Untitled Feed" );
|
title = BString( "Untitled Feed" );
|
||||||
description = BString( "Nondescript, N/A." );
|
description = BString( "Nondescript, N/A." );
|
||||||
homeUrl = BString("");
|
homeUrl = BString("");
|
||||||
xmlUrl = BString("");
|
xmlUrl = BString("");
|
||||||
updated = true;
|
updated = true;
|
||||||
filePath = GetCachePath( path, cfg );
|
filePath = GetCachePath( path );
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed::Feed ( )
|
Feed::Feed ( )
|
||||||
|
@ -25,14 +26,14 @@ Feed::Feed ( )
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
Feed::Parse ( Config* cfg )
|
Feed::Parse ( )
|
||||||
{
|
{
|
||||||
BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY );
|
BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY );
|
||||||
time_t tt_lastDate = 0;
|
time_t tt_lastDate = 0;
|
||||||
BDateTime attrLastDate = BDateTime();
|
BDateTime attrLastDate = BDateTime();
|
||||||
|
|
||||||
feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) );
|
feedFile->ReadAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) );
|
||||||
if ( tt_lastDate > 0 && cfg->updateFeeds == true ) {
|
if ( tt_lastDate > 0 && ((App*)be_app)->cfg->updateFeeds == true ) {
|
||||||
attrLastDate.SetTime_t( tt_lastDate );
|
attrLastDate.SetTime_t( tt_lastDate );
|
||||||
minDate = attrLastDate;
|
minDate = attrLastDate;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +42,7 @@ Feed::Parse ( Config* cfg )
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
|
||||||
BString
|
BString
|
||||||
Feed::GetCachePath ( BString givenPath, Config* cfg )
|
Feed::GetCachePath ( BString givenPath )
|
||||||
{
|
{
|
||||||
BUrl givenUrl = BUrl( givenPath );
|
BUrl givenUrl = BUrl( givenPath );
|
||||||
BString protocol = givenUrl.Protocol().String();
|
BString protocol = givenUrl.Protocol().String();
|
||||||
|
@ -51,11 +52,11 @@ Feed::GetCachePath ( BString givenPath, Config* cfg )
|
||||||
if ( protocol != BString("http") && protocol != BString("https") )
|
if ( protocol != BString("http") && protocol != BString("https") )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return FetchRemoteFeed( givenPath, cfg );
|
return FetchRemoteFeed( givenPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
BString
|
BString
|
||||||
Feed::FetchRemoteFeed ( BString givenPath, Config* cfg )
|
Feed::FetchRemoteFeed ( BString givenPath )
|
||||||
{
|
{
|
||||||
BUrl givenUrl = BUrl( givenPath );
|
BUrl givenUrl = BUrl( givenPath );
|
||||||
time_t tt_lastDate = 0;
|
time_t tt_lastDate = 0;
|
||||||
|
@ -67,13 +68,13 @@ Feed::FetchRemoteFeed ( BString givenPath, Config* cfg )
|
||||||
splitName.Append( givenUrl.Path() );
|
splitName.Append( givenUrl.Path() );
|
||||||
splitName.ReplaceAll("/", "_");
|
splitName.ReplaceAll("/", "_");
|
||||||
|
|
||||||
BString filename = cfg->cacheDir;
|
BString filename = ((App*)be_app)->cfg->cacheDir;
|
||||||
filename.Append(splitName);
|
filename.Append(splitName);
|
||||||
BFile* cacheFile = new BFile( filename, B_READ_WRITE | B_CREATE_FILE );
|
BFile* cacheFile = new BFile( filename, B_READ_WRITE | B_CREATE_FILE );
|
||||||
|
|
||||||
cacheFile->ReadAttr( "LastHash", B_STRING_TYPE, 0, oldHash, 41 );
|
cacheFile->ReadAttr( "LastHash", B_STRING_TYPE, 0, oldHash, 41 );
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( ((App*)be_app)->cfg->verbose )
|
||||||
printf( "Saving %s...\n", givenPath.String() );
|
printf( "Saving %s...\n", givenPath.String() );
|
||||||
|
|
||||||
webFetch( givenUrl, cacheFile, newHash );
|
webFetch( givenUrl, cacheFile, newHash );
|
||||||
|
@ -127,8 +128,9 @@ Feed::xmlCountSiblings ( tinyxml2::XMLElement* xsibling, const char* sibling_nam
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Feed::AddEntry ( Config* cfg, Entry* newEntry )
|
Feed::AddEntry ( Entry* newEntry )
|
||||||
{
|
{
|
||||||
|
Config* cfg = ((App*)be_app)->cfg;
|
||||||
if ( !withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) ||
|
if ( !withinDateRange( cfg->minDate, newEntry->date, cfg->maxDate ) ||
|
||||||
!withinDateRange( minDate, newEntry->date, maxDate ) )
|
!withinDateRange( minDate, newEntry->date, maxDate ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
11
src/Feed.h
11
src/Feed.h
|
@ -7,11 +7,10 @@
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <Url.h>
|
#include <Url.h>
|
||||||
#include "Entry.h"
|
#include "Entry.h"
|
||||||
#include "Config.h"
|
|
||||||
|
|
||||||
class Feed {
|
class Feed {
|
||||||
public:
|
public:
|
||||||
Feed ( BString, Config* );
|
Feed ( BString );
|
||||||
Feed ( );
|
Feed ( );
|
||||||
|
|
||||||
BString title;
|
BString title;
|
||||||
|
@ -27,9 +26,9 @@ public:
|
||||||
BList entries;
|
BList entries;
|
||||||
bool updated;
|
bool updated;
|
||||||
|
|
||||||
virtual void Parse ( Config* );
|
virtual void Parse ( );
|
||||||
|
|
||||||
bool AddEntry ( Config*, Entry* );
|
bool AddEntry ( Entry* );
|
||||||
bool SetTitle ( const char* );
|
bool SetTitle ( const char* );
|
||||||
bool SetTitle ( tinyxml2::XMLElement* );
|
bool SetTitle ( tinyxml2::XMLElement* );
|
||||||
bool SetDesc ( const char* );
|
bool SetDesc ( const char* );
|
||||||
|
@ -43,8 +42,8 @@ public:
|
||||||
bool IsAtom ( );
|
bool IsAtom ( );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BString GetCachePath ( BString, Config* );
|
BString GetCachePath ( BString );
|
||||||
BString FetchRemoteFeed ( BString, Config* );
|
BString FetchRemoteFeed ( BString );
|
||||||
int xmlCountSiblings ( tinyxml2::XMLElement*, const char* );
|
int xmlCountSiblings ( tinyxml2::XMLElement*, const char* );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@ usage ( )
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
invocation ( int argc, char** argv, Config** cfgPtr )
|
invocation ( int argc, char** argv )
|
||||||
{
|
{
|
||||||
Config* cfg = *(cfgPtr);
|
Config* cfg = ((App*)be_app)->cfg;
|
||||||
BDateTime maxDate;
|
BDateTime maxDate;
|
||||||
BDateTime minDate;
|
BDateTime minDate;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case -1:
|
case -1:
|
||||||
freeargInvocation( argc, argv, optind, cfgPtr );
|
freeargInvocation( argc, argv, optind );
|
||||||
return 0;
|
return 0;
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage();
|
return usage();
|
||||||
|
@ -100,9 +100,9 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
freeargInvocation ( int argc, char** argv, int optind, Config** cfgPtr )
|
freeargInvocation ( int argc, char** argv, int optind )
|
||||||
{
|
{
|
||||||
Config* cfg = *(cfgPtr);
|
Config* cfg = ((App*)be_app)->cfg;
|
||||||
if ( optind < argc ) {
|
if ( optind < argc ) {
|
||||||
int freeargc = argc - optind;
|
int freeargc = argc - optind;
|
||||||
cfg->targetFeeds = BList( freeargc );
|
cfg->targetFeeds = BList( freeargc );
|
||||||
|
@ -120,7 +120,7 @@ bool
|
||||||
processEntry ( void* entry )
|
processEntry ( void* entry )
|
||||||
{
|
{
|
||||||
Entry* entryPtr = (Entry*)entry;
|
Entry* entryPtr = (Entry*)entry;
|
||||||
entryPtr->Filetize( main_cfg, false );
|
entryPtr->Filetize( false );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,22 +128,22 @@ bool
|
||||||
processFeed ( void* feedArg )
|
processFeed ( void* feedArg )
|
||||||
{
|
{
|
||||||
BString* feedStr = (BString*)feedArg;
|
BString* feedStr = (BString*)feedArg;
|
||||||
Feed* testFeed = new Feed( *(feedStr), main_cfg );
|
Feed* testFeed = new Feed( *(feedStr) );
|
||||||
BList entries;
|
BList entries;
|
||||||
|
|
||||||
if ( testFeed->updated == false && main_cfg->updateFeeds == true )
|
if ( testFeed->updated == false && ((App*)be_app)->cfg->updateFeeds == true )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( testFeed->IsAtom() ) {
|
if ( testFeed->IsAtom() ) {
|
||||||
AtomFeed* feed = (AtomFeed*)malloc( sizeof(AtomFeed) );
|
AtomFeed* feed = (AtomFeed*)malloc( sizeof(AtomFeed) );
|
||||||
feed = new AtomFeed( testFeed, main_cfg );
|
feed = new AtomFeed( testFeed );
|
||||||
feed->Parse(main_cfg);
|
feed->Parse();
|
||||||
entries = feed->entries;
|
entries = feed->entries;
|
||||||
}
|
}
|
||||||
if ( testFeed->IsRss() ) {
|
if ( testFeed->IsRss() ) {
|
||||||
RssFeed* feed = (RssFeed*)malloc( sizeof(RssFeed) );
|
RssFeed* feed = (RssFeed*)malloc( sizeof(RssFeed) );
|
||||||
feed = new RssFeed( testFeed, main_cfg );
|
feed = new RssFeed( testFeed );
|
||||||
feed->Parse(main_cfg);
|
feed->Parse();
|
||||||
entries = feed->entries;
|
entries = feed->entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
#include <StorageKit.h>
|
#include <StorageKit.h>
|
||||||
|
|
||||||
int usage ( );
|
int usage ( );
|
||||||
int invocation ( int, char**, Config** );
|
int invocation ( int, char** );
|
||||||
void freeargInvocation ( int, char**, int, Config** );
|
void freeargInvocation ( int, char**, int );
|
||||||
bool processItem ( void* );
|
bool processItem ( void* );
|
||||||
bool processFeed ( void* );
|
bool processFeed ( void* );
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
#include "Entry.h"
|
#include "Entry.h"
|
||||||
|
#include "App.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "RssFeed.h"
|
#include "RssFeed.h"
|
||||||
|
@ -10,31 +11,27 @@ RssFeed::RssFeed ( )
|
||||||
description = BString("");
|
description = BString("");
|
||||||
homeUrl = BString("");
|
homeUrl = BString("");
|
||||||
xmlUrl = BString("");
|
xmlUrl = BString("");
|
||||||
|
outputDir = ((App*)be_app)->cfg->outDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
RssFeed::RssFeed ( Feed* feed ) : RssFeed::RssFeed()
|
RssFeed::RssFeed ( Feed* feed ) : RssFeed::RssFeed()
|
||||||
{ filePath = feed->filePath; }
|
{ filePath = feed->filePath; }
|
||||||
RssFeed::RssFeed ( Feed* feed, Config* cfg ) : RssFeed::RssFeed( feed )
|
|
||||||
{ outputDir = cfg->outDir; }
|
|
||||||
RssFeed::RssFeed ( Config* cfg ) : RssFeed::RssFeed( )
|
|
||||||
{ outputDir = cfg->outDir; }
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
RssFeed::Parse ( Config* cfg )
|
RssFeed::Parse ( )
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument xml;
|
tinyxml2::XMLDocument xml;
|
||||||
entries = BList();
|
entries = BList();
|
||||||
|
|
||||||
Feed::Parse( cfg );
|
Feed::Parse();
|
||||||
|
|
||||||
xml.LoadFile( filePath.String() );
|
xml.LoadFile( filePath.String() );
|
||||||
tinyxml2::XMLElement* xchan = xml.FirstChildElement("rss")->FirstChildElement("channel");
|
tinyxml2::XMLElement* xchan = xml.FirstChildElement("rss")->FirstChildElement("channel");
|
||||||
|
|
||||||
RootParse( cfg, xchan );
|
RootParse( xchan );
|
||||||
ParseEntries( cfg, xchan );
|
ParseEntries( xchan );
|
||||||
|
|
||||||
time_t tt_lastDate = lastDate.Time_t();
|
time_t tt_lastDate = lastDate.Time_t();
|
||||||
BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY );
|
BFile* feedFile = new BFile( filePath.String(), B_READ_ONLY );
|
||||||
|
@ -44,19 +41,19 @@ RssFeed::Parse ( Config* cfg )
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
RssFeed::RootParse ( Config* cfg, tinyxml2::XMLElement* xchan )
|
RssFeed::RootParse ( tinyxml2::XMLElement* xchan )
|
||||||
{
|
{
|
||||||
SetTitle ( xchan->FirstChildElement("title") );
|
SetTitle ( xchan->FirstChildElement("title") );
|
||||||
SetDesc ( xchan->FirstChildElement("description") );
|
SetDesc ( xchan->FirstChildElement("description") );
|
||||||
SetHomeUrl ( xchan->FirstChildElement("link") );
|
SetHomeUrl ( xchan->FirstChildElement("link") );
|
||||||
SetDate ( xchan->FirstChildElement("lastBuildDate") );
|
SetDate ( xchan->FirstChildElement("lastBuildDate") );
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( ((App*)be_app)->cfg->verbose )
|
||||||
printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String());
|
printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RssFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xitem )
|
RssFeed::EntryParse ( tinyxml2::XMLElement* xitem )
|
||||||
{
|
{
|
||||||
Entry* newEntry = (Entry*)malloc( sizeof(Entry) );
|
Entry* newEntry = (Entry*)malloc( sizeof(Entry) );
|
||||||
newEntry = new Entry( outputDir );
|
newEntry = new Entry( outputDir );
|
||||||
|
@ -71,11 +68,11 @@ RssFeed::EntryParse ( Config* cfg, tinyxml2::XMLElement* xitem )
|
||||||
if ( lastDate == NULL || lastDate < newEntry->date )
|
if ( lastDate == NULL || lastDate < newEntry->date )
|
||||||
lastDate = newEntry->date;
|
lastDate = newEntry->date;
|
||||||
|
|
||||||
AddEntry( cfg, newEntry );
|
AddEntry( newEntry );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RssFeed::ParseEntries ( Config* cfg, tinyxml2::XMLElement* xchan )
|
RssFeed::ParseEntries ( tinyxml2::XMLElement* xchan )
|
||||||
{
|
{
|
||||||
tinyxml2::XMLElement* xitem;
|
tinyxml2::XMLElement* xitem;
|
||||||
|
|
||||||
|
@ -84,11 +81,11 @@ RssFeed::ParseEntries ( Config* cfg, tinyxml2::XMLElement* xchan )
|
||||||
int entryCount = xmlCountSiblings( xitem, "item" );
|
int entryCount = xmlCountSiblings( xitem, "item" );
|
||||||
entries = BList(entryCount);
|
entries = BList(entryCount);
|
||||||
|
|
||||||
if ( cfg->verbose )
|
if ( ((App*)be_app)->cfg->verbose )
|
||||||
printf("\t-%i entries-\n", entryCount);
|
printf("\t-%i entries-\n", entryCount);
|
||||||
|
|
||||||
while ( xitem ) {
|
while ( xitem ) {
|
||||||
EntryParse( cfg, xitem );
|
EntryParse( xitem );
|
||||||
xitem = xitem->NextSiblingElement("item");
|
xitem = xitem->NextSiblingElement("item");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,20 +6,17 @@
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <Url.h>
|
#include <Url.h>
|
||||||
#include "Config.h"
|
|
||||||
#include "Feed.h"
|
#include "Feed.h"
|
||||||
|
|
||||||
class RssFeed: public Feed {
|
class RssFeed: public Feed {
|
||||||
public:
|
public:
|
||||||
RssFeed ( );
|
RssFeed ( );
|
||||||
RssFeed ( Feed*, Config* );
|
|
||||||
RssFeed ( Feed* );
|
RssFeed ( Feed* );
|
||||||
RssFeed ( Config* );
|
|
||||||
|
|
||||||
void Parse ( Config* );
|
void Parse ( );
|
||||||
void RootParse ( Config*, tinyxml2::XMLElement* );
|
void RootParse ( tinyxml2::XMLElement* );
|
||||||
void EntryParse ( Config*, tinyxml2::XMLElement* );
|
void EntryParse ( tinyxml2::XMLElement* );
|
||||||
void ParseEntries ( Config*, tinyxml2::XMLElement* );
|
void ParseEntries ( tinyxml2::XMLElement* );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Ŝarĝante…
Reference in New Issue