Support HTTP(S) feeds (start cache)
This commit is contained in:
parent
6b7756f50b
commit
e69646a42c
1
Makefile
1
Makefile
|
@ -36,7 +36,6 @@ SRCS = \
|
||||||
src/ProtocolListener.cpp, \
|
src/ProtocolListener.cpp, \
|
||||||
src/Config.cpp, \
|
src/Config.cpp, \
|
||||||
src/Util.cpp, \
|
src/Util.cpp, \
|
||||||
src/parsing.cpp, \
|
|
||||||
src/Pogger.cpp
|
src/Pogger.cpp
|
||||||
|
|
||||||
# Specify the resource definition files to use. Full or relative paths can be
|
# Specify the resource definition files to use. Full or relative paths can be
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "AtomFeed.h"
|
#include "AtomFeed.h"
|
||||||
|
|
||||||
AtomFeed::AtomFeed ( BString path, BString outputPath )
|
AtomFeed::AtomFeed ( BString path, Config* cfg )
|
||||||
{
|
{
|
||||||
title = BString("Untitled Feed");
|
title = BString("Untitled Feed");
|
||||||
description = BString("");
|
description = BString("");
|
||||||
homeUrl = BString("");
|
homeUrl = BString("");
|
||||||
xmlUrl = BString("");
|
xmlUrl = BString("");
|
||||||
filePath = path;
|
filePath = path;
|
||||||
outputDir = outputPath;
|
outputDir = cfg->outDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
class AtomFeed: public Feed {
|
class AtomFeed: public Feed {
|
||||||
public:
|
public:
|
||||||
AtomFeed ( BString, BString );
|
AtomFeed ( BString, Config* );
|
||||||
|
|
||||||
void Parse ( Config* );
|
void Parse ( Config* );
|
||||||
void RootParse ( Config*, tinyxml2::XMLElement* );
|
void RootParse ( Config*, tinyxml2::XMLElement* );
|
||||||
|
|
|
@ -6,16 +6,17 @@ Config::Config () {
|
||||||
verbose = false;
|
verbose = false;
|
||||||
daemon = true;
|
daemon = true;
|
||||||
will_save = false;
|
will_save = false;
|
||||||
|
updateFeeds = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// !! handle file status
|
// !! handle file status
|
||||||
void
|
void
|
||||||
Config::Load ()
|
Config::Load ()
|
||||||
{
|
{
|
||||||
if ( configPath == NULL )
|
if ( configDir == NULL )
|
||||||
configPath = BString( "/boot/home/config/settings/Pogger/" );
|
configDir = BString( "/boot/home/config/settings/Pogger/" );
|
||||||
|
|
||||||
BString filename = BString(configPath);
|
BString filename = BString(configDir);
|
||||||
filename.Append("settings");
|
filename.Append("settings");
|
||||||
BFile* file = new BFile( filename.String(), B_READ_ONLY );
|
BFile* file = new BFile( filename.String(), B_READ_ONLY );
|
||||||
status_t result = file->InitCheck();
|
status_t result = file->InitCheck();
|
||||||
|
@ -27,8 +28,8 @@ Config::Load ()
|
||||||
mimetype = BString( storage.GetString("mimetype", "text/xml") );
|
mimetype = BString( storage.GetString("mimetype", "text/xml") );
|
||||||
if ( outDir == NULL)
|
if ( outDir == NULL)
|
||||||
outDir = BString( storage.GetString("outDir", "/boot/home/feeds/") );
|
outDir = BString( storage.GetString("outDir", "/boot/home/feeds/") );
|
||||||
// if ( cacheDir == NULL)
|
if ( cacheDir == NULL)
|
||||||
// cacheDir = BString( storage.GetString("cacheDir", "/boot/home/config/cache/Pogger/") );
|
cacheDir = BString( storage.GetString("cacheDir", "/boot/home/config/cache/Pogger/") );
|
||||||
delete file;
|
delete file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,10 +37,10 @@ Config::Load ()
|
||||||
void
|
void
|
||||||
Config::Save ()
|
Config::Save ()
|
||||||
{
|
{
|
||||||
if ( configPath == NULL )
|
if ( configDir == NULL )
|
||||||
configPath = BString( "/boot/home/config/settings/Pogger/" );
|
configDir = BString( "/boot/home/config/settings/Pogger/" );
|
||||||
|
|
||||||
BPath* cfgPath = new BPath( configPath.String(), NULL, true );
|
BPath* cfgPath = new BPath( configDir.String(), NULL, true );
|
||||||
BEntry* cfgEntry = new BEntry( cfgPath->Path() );
|
BEntry* cfgEntry = new BEntry( cfgPath->Path() );
|
||||||
BDirectory* cfgDir = new BDirectory;
|
BDirectory* cfgDir = new BDirectory;
|
||||||
|
|
||||||
|
@ -49,14 +50,14 @@ Config::Save ()
|
||||||
cfgDir->CreateDirectory( cfgPath->Path(), NULL );
|
cfgDir->CreateDirectory( cfgPath->Path(), NULL );
|
||||||
|
|
||||||
BMessage storage;
|
BMessage storage;
|
||||||
BString filename = BString( configPath ).Append("/settings");
|
BString filename = BString( configDir ).Append("/settings");
|
||||||
|
|
||||||
BFile* file = new BFile( filename.String(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
|
BFile* file = new BFile( filename.String(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
|
||||||
status_t result = file->InitCheck();
|
status_t result = file->InitCheck();
|
||||||
|
|
||||||
storage.AddString( "mimetype", mimetype.String() );
|
storage.AddString( "mimetype", mimetype.String() );
|
||||||
storage.AddString( "outDir", outDir.String() );
|
storage.AddString( "outDir", outDir.String() );
|
||||||
// storage.AddString( "cacheDir", cacheDir.String() );
|
storage.AddString( "cacheDir", cacheDir.String() );
|
||||||
|
|
||||||
storage.Flatten( file );
|
storage.Flatten( file );
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,12 @@ public:
|
||||||
BDateTime minDate;
|
BDateTime minDate;
|
||||||
BDateTime maxDate;
|
BDateTime maxDate;
|
||||||
|
|
||||||
BString configPath;
|
BString configDir;
|
||||||
|
BString cacheDir;
|
||||||
bool will_save;
|
bool will_save;
|
||||||
|
|
||||||
|
bool updateFeeds;
|
||||||
|
|
||||||
Config ( );
|
Config ( );
|
||||||
|
|
||||||
void Load ( );
|
void Load ( );
|
||||||
|
|
39
src/Feed.cpp
39
src/Feed.cpp
|
@ -4,16 +4,17 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "Feed.h"
|
#include "Feed.h"
|
||||||
|
|
||||||
Feed::Feed ( BString path )
|
Feed::Feed ( BString path, Config* cfg )
|
||||||
{
|
{
|
||||||
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("");
|
||||||
filePath = path;
|
|
||||||
|
filePath = GetCachePath( path, cfg );
|
||||||
}
|
}
|
||||||
|
|
||||||
Feed::Feed () {
|
Feed::Feed ( ) {
|
||||||
title = BString("");
|
title = BString("");
|
||||||
description = BString("");
|
description = BString("");
|
||||||
homeUrl = BString("");
|
homeUrl = BString("");
|
||||||
|
@ -22,6 +23,34 @@ Feed::Feed () {
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
BString
|
||||||
|
Feed::GetCachePath ( BString falsePath, Config* cfg )
|
||||||
|
{
|
||||||
|
BUrl falseUrl = BUrl(falsePath);
|
||||||
|
BString protocol = falseUrl.Protocol().String();
|
||||||
|
|
||||||
|
if ( protocol == NULL && falseUrl.UrlString() != NULL )
|
||||||
|
return falsePath;
|
||||||
|
if ( protocol != BString("http") && protocol != BString("https") )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
BString splitName = falseUrl.Host( );
|
||||||
|
splitName.Append( falseUrl.Path() );
|
||||||
|
splitName.ReplaceAll("/", "_");
|
||||||
|
|
||||||
|
BString filename = cfg->cacheDir;
|
||||||
|
filename.Append(splitName);
|
||||||
|
BFile* cacheFile = new BFile( filename, B_READ_WRITE | B_CREATE_FILE );
|
||||||
|
|
||||||
|
if ( cfg->verbose )
|
||||||
|
printf( "Saving %s to %s...\n", falsePath.String(), filename.String() );
|
||||||
|
|
||||||
|
webFetch( falseUrl, cacheFile );
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Feed::IsRss ( )
|
Feed::IsRss ( )
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
class Feed {
|
class Feed {
|
||||||
public:
|
public:
|
||||||
Feed ( BString );
|
Feed ( BString, Config* );
|
||||||
Feed ( );
|
Feed ( );
|
||||||
|
|
||||||
BString title;
|
BString title;
|
||||||
|
@ -37,6 +37,7 @@ public:
|
||||||
bool IsAtom ( );
|
bool IsAtom ( );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
BString GetCachePath ( BString, Config* );
|
||||||
int xmlCountSiblings ( tinyxml2::XMLElement*, const char* );
|
int xmlCountSiblings ( tinyxml2::XMLElement*, const char* );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ main ( int argc, char** argv )
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
int
|
int
|
||||||
usage ()
|
usage ( )
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s", usageMsg.String());
|
fprintf(stderr, "%s", usageMsg.String());
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -45,6 +45,7 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
{ "help", no_argument, 0, 'h' },
|
{ "help", no_argument, 0, 'h' },
|
||||||
{ "verbose", no_argument, 0, 'v' },
|
{ "verbose", no_argument, 0, 'v' },
|
||||||
{ "config", required_argument, 0, 'c' },
|
{ "config", required_argument, 0, 'c' },
|
||||||
|
{ "cache", required_argument, 0, 'C' },
|
||||||
{ "before", required_argument, 0, 't' },
|
{ "before", required_argument, 0, 't' },
|
||||||
{ "after", required_argument, 0, 'T' },
|
{ "after", required_argument, 0, 'T' },
|
||||||
{ "output", required_argument, 0, 'O' },
|
{ "output", required_argument, 0, 'O' },
|
||||||
|
@ -55,7 +56,7 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
opterr = 0;
|
opterr = 0;
|
||||||
int c = getopt_long(argc, argv, "+hsvDm:O:T:t:c:", sLongOptions, NULL);
|
int c = getopt_long(argc, argv, "+hsvDm:O:T:t:c:C:", sLongOptions, NULL);
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -64,7 +65,10 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage();
|
return usage();
|
||||||
case 'c':
|
case 'c':
|
||||||
cfg->configPath = BString( optarg );
|
cfg->configDir = BString( optarg );
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
cfg->cacheDir = BString( optarg );
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
cfg->will_save = true;
|
cfg->will_save = true;
|
||||||
|
@ -140,18 +144,20 @@ bool
|
||||||
processFeed ( void* feedArg )
|
processFeed ( void* feedArg )
|
||||||
{
|
{
|
||||||
BString* feedStr = (BString*)feedArg;
|
BString* feedStr = (BString*)feedArg;
|
||||||
Feed* testFeed = new Feed( *(feedStr) );
|
Feed* testFeed = new Feed( *(feedStr), main_cfg );
|
||||||
BList entries;
|
BList entries;
|
||||||
|
|
||||||
if ( testFeed->IsAtom() ) {
|
if ( testFeed->IsAtom() ) {
|
||||||
|
printf("Atom\n");
|
||||||
AtomFeed* feed = (AtomFeed*)malloc( sizeof(AtomFeed) );
|
AtomFeed* feed = (AtomFeed*)malloc( sizeof(AtomFeed) );
|
||||||
feed = new AtomFeed( *(feedStr), main_cfg->outDir );
|
feed = new AtomFeed( testFeed->filePath, main_cfg );
|
||||||
feed->Parse(main_cfg);
|
feed->Parse(main_cfg);
|
||||||
entries = feed->entries;
|
entries = feed->entries;
|
||||||
}
|
}
|
||||||
if ( testFeed->IsRss() ) {
|
if ( testFeed->IsRss() ) {
|
||||||
|
printf("RSS\n");
|
||||||
RssFeed* feed = (RssFeed*)malloc( sizeof(RssFeed) );
|
RssFeed* feed = (RssFeed*)malloc( sizeof(RssFeed) );
|
||||||
feed = new RssFeed( *(feedStr), main_cfg->outDir );
|
feed = new RssFeed( testFeed->filePath, main_cfg );
|
||||||
feed->Parse(main_cfg);
|
feed->Parse(main_cfg);
|
||||||
entries = feed->entries;
|
entries = feed->entries;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
class ProtocolListener : public BUrlProtocolListener
|
class ProtocolListener : public BUrlProtocolListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProtocolListener(bool traceLogging);
|
ProtocolListener ( bool );
|
||||||
|
|
||||||
virtual ~ProtocolListener();
|
virtual ~ProtocolListener();
|
||||||
virtual void DataReceived(BUrlRequest*, const char*, off_t, ssize_t);
|
virtual void DataReceived(BUrlRequest*, const char*, off_t, ssize_t);
|
||||||
|
|
|
@ -4,14 +4,14 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "RssFeed.h"
|
#include "RssFeed.h"
|
||||||
|
|
||||||
RssFeed::RssFeed ( BString path, BString outputPath )
|
RssFeed::RssFeed ( BString path, Config* cfg )
|
||||||
{
|
{
|
||||||
title = BString("Untitled Feed");
|
title = BString("Untitled Feed");
|
||||||
description = BString("");
|
description = BString("");
|
||||||
homeUrl = BString("");
|
homeUrl = BString("");
|
||||||
xmlUrl = BString("");
|
xmlUrl = BString("");
|
||||||
filePath = path;
|
filePath = path;
|
||||||
outputDir = outputPath;
|
outputDir = cfg->outDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
class RssFeed: public Feed {
|
class RssFeed: public Feed {
|
||||||
public:
|
public:
|
||||||
RssFeed ( BString, BString );
|
RssFeed ( BString, Config* );
|
||||||
|
|
||||||
void Parse ( Config* );
|
void Parse ( Config* );
|
||||||
void RootParse ( Config*, tinyxml2::XMLElement* );
|
void RootParse ( Config*, tinyxml2::XMLElement* );
|
||||||
|
|
Ŝarĝante…
Reference in New Issue