Direly needed reformatting

This commit is contained in:
Jaidyn Ann 2020-12-30 22:07:54 -06:00
parent f46a53fdc5
commit 85923f2cc2
22 changed files with 839 additions and 547 deletions

View File

@ -29,17 +29,18 @@ 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/Feed.cpp, \
src/Entry.cpp, \
src/AtomFeed.cpp, \
src/RssFeed.cpp, \
src/PrefWindow.cpp, \
src/ProtocolListener.cpp, \
src/Mimetypes.cpp, \
src/Config.cpp, \
src/Util.cpp, \
src/App.cpp, \ src/App.cpp, \
src/AtomFeed.cpp, \
src/Config.cpp, \
src/Entry.cpp, \
src/Feed.cpp, \
src/FeedView.cpp, \
src/Invocation.cpp \ src/Invocation.cpp \
src/MainWindow.cpp, \
src/Mimetypes.cpp, \
src/ProtocolListener.cpp, \
src/RssFeed.cpp, \
src/Util.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
# used. # used.

View File

@ -112,5 +112,5 @@ Sry bby, i'm trying <3
BORING INFO BORING INFO
-------------------------------------------------- --------------------------------------------------
Pogger is under the MIT license. Pogger is under the MIT license.
https://git.xwx.moe/pogger.git https://git.feneas.org/detruota/pogger
jadedctrl@teknik.io jadedctrl@teknik.io

View File

@ -1,16 +1,24 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "App.h"
#include <StorageKit.h> #include <StorageKit.h>
#include <String.h> #include <String.h>
#include <getopt.h> #include <getopt.h>
#include "AtomFeed.h" #include "AtomFeed.h"
#include "RssFeed.h"
#include "Feed.h"
#include "Entry.h"
#include "Mimetypes.h"
#include "Config.h" #include "Config.h"
#include "Util.h" #include "Entry.h"
#include "App.h" #include "Feed.h"
#include "MainWindow.h"
#include "Invocation.h" #include "Invocation.h"
#include "MainWindow.h"
#include "Mimetypes.h"
#include "RssFeed.h"
#include "Util.h"
int int
@ -36,7 +44,6 @@ main ( int argc, char** argv )
return 0; return 0;
} }
// -------------------------------------
void void
cliStart(int argc, char** argv) cliStart(int argc, char** argv)
@ -45,16 +52,14 @@ cliStart ( int argc, char** argv )
((App*)be_app)->cfg->targetFeeds.DoForEach(&processFeed); ((App*)be_app)->cfg->targetFeeds.DoForEach(&processFeed);
} }
App::App ( )
: BApplication("application/x-vnd.Pogger") App::App() : BApplication("application/x-vnd.Pogger")
{ {
MainWindow* mainWin = new MainWindow(); MainWindow* mainWin = new MainWindow();
mainWin->Show(); mainWin->Show();
} }
// ----------------------------------------------------------------------------
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"

View File

@ -1,9 +1,16 @@
#ifndef APPP_H /*
#define APPP_H * Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef APP_H
#define APP_H
#include <SupportDefs.h> #include <SupportDefs.h>
#include <Application.h> #include <Application.h>
#include "Config.h"
class Config;
class App : public BApplication class App : public BApplication
@ -13,14 +20,14 @@ public:
Config* cfg; Config* cfg;
}; };
// ----------------------------------------------------------------------------
int main ( int, char** ); int main ( int, char** );
void cliStart ( int, char** ); void cliStart ( int, char** );
// ----------------------------------------------------------------------------
extern const char* configPath; extern const char* configPath;
extern BString usageMsg; extern BString usageMsg;
#endif #endif

View File

@ -1,9 +1,17 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "AtomFeed.h"
#include <tinyxml2.h> #include <tinyxml2.h>
#include "Entry.h"
#include "App.h" #include "App.h"
#include "Config.h" #include "Config.h"
#include "Entry.h"
#include "Util.h" #include "Util.h"
#include "AtomFeed.h"
AtomFeed::AtomFeed() AtomFeed::AtomFeed()
{ {
@ -15,10 +23,13 @@ AtomFeed::AtomFeed ( )
outputDir = ((App*)be_app)->cfg->outDir; outputDir = ((App*)be_app)->cfg->outDir;
} }
AtomFeed::AtomFeed ( Feed* feed ) : AtomFeed::AtomFeed()
{ SetCachePath( feed->GetCachePath() ); }
// ---------------------------------------------------------------------------- AtomFeed::AtomFeed(Feed* feed)
: AtomFeed::AtomFeed()
{
SetCachePath(feed->GetCachePath());
}
void void
AtomFeed::Parse () AtomFeed::Parse ()
@ -36,9 +47,11 @@ AtomFeed::Parse ( )
BFile* feedFile = new BFile(GetCachePath().String(), B_READ_WRITE); BFile* feedFile = new BFile(GetCachePath().String(), B_READ_WRITE);
time_t tt_lastDate = lastDate.Time_t(); time_t tt_lastDate = lastDate.Time_t();
feedFile->WriteAttr( "LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t) ); feedFile->WriteAttr("LastDate", B_TIME_TYPE, 0, &tt_lastDate,
sizeof(time_t));
} }
void void
AtomFeed::RootParse(tinyxml2::XMLElement* xfeed) AtomFeed::RootParse(tinyxml2::XMLElement* xfeed)
{ {
@ -53,18 +66,24 @@ AtomFeed::RootParse( tinyxml2::XMLElement* xfeed )
SetDesc( xfeed->FirstChildElement("description")); SetDesc( xfeed->FirstChildElement("description"));
set = SetDate(xfeed->FirstChildElement("updated")); set = SetDate(xfeed->FirstChildElement("updated"));
if ( !set ) set = SetDate( xfeed->FirstChildElement("published") ); if (!set)
if ( !set && xentry ) set = SetDate( xentry->FirstChildElement("updated") ); set = SetDate(xfeed->FirstChildElement("published"));
if ( !set && xentry ) set = SetDate( xentry->FirstChildElement("published") ); if (!set && xentry)
set = SetDate(xentry->FirstChildElement("updated"));
if (!set && xentry)
set = SetDate(xentry->FirstChildElement("published"));
set = SetHomeUrl(xlink->Attribute("href")); set = SetHomeUrl(xlink->Attribute("href"));
if ( !set && xauthor ) set = SetHomeUrl( xauthor->FirstChildElement("uri") ); if (!set && xauthor)
if ( !set && xauthlink ) set = SetHomeUrl( xauthlink->Attribute( "href" ) ); set = SetHomeUrl(xauthor->FirstChildElement("uri"));
if (!set && xauthlink)
set = SetHomeUrl(xauthlink->Attribute("href"));
if (((App*)be_app)->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(tinyxml2::XMLElement* xentry) AtomFeed::EntryParse(tinyxml2::XMLElement* xentry)
{ {
@ -81,11 +100,14 @@ AtomFeed::EntryParse ( tinyxml2::XMLElement* xentry )
bool set = false; bool set = false;
set = newEntry->SetDesc(xentry->FirstChildElement("summary")); set = newEntry->SetDesc(xentry->FirstChildElement("summary"));
if ( !set ) set = newEntry->SetDesc( xentry->FirstChildElement("description")); if (!set)
if ( !set && xmedia ) set = newEntry->SetDesc( xmedia->FirstChildElement("media:description")); set = newEntry->SetDesc(xentry->FirstChildElement("description"));
if (!set && xmedia)
set = newEntry->SetDesc(xmedia->FirstChildElement("media:description"));
set = newEntry->SetDate(xentry->FirstChildElement("updated")); set = newEntry->SetDate(xentry->FirstChildElement("updated"));
if ( !set ) set = newEntry->SetDate( xentry->FirstChildElement("published") ); if (!set)
set = newEntry->SetDate(xentry->FirstChildElement("published"));
if (lastDate == NULL || lastDate < newEntry->date) if (lastDate == NULL || lastDate < newEntry->date)
lastDate = newEntry->date; lastDate = newEntry->date;
@ -98,6 +120,7 @@ AtomFeed::EntryParse ( tinyxml2::XMLElement* xentry )
AddEntry(newEntry); AddEntry(newEntry);
} }
void void
AtomFeed::ParseEntries(tinyxml2::XMLElement* xfeed) AtomFeed::ParseEntries(tinyxml2::XMLElement* xfeed)
{ {

View File

@ -1,14 +1,16 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef ATOM_FEED_H #ifndef ATOM_FEED_H
#define ATOM_FEED_H #define ATOM_FEED_H
#include <tinyxml2.h> #include <tinyxml2.h>
#include <DateTime.h>
#include <String.h>
#include <List.h>
#include <Url.h>
#include "Config.h"
#include "Feed.h" #include "Feed.h"
class AtomFeed: public Feed { class AtomFeed: public Feed {
public: public:
AtomFeed(); AtomFeed();
@ -20,4 +22,6 @@ public:
void ParseEntries(tinyxml2::XMLElement*); void ParseEntries(tinyxml2::XMLElement*);
}; };
#endif #endif

View File

@ -1,7 +1,15 @@
#include <iostream> /*
#include <String.h> * Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "Config.h" #include "Config.h"
#include <String.h>
#include <iostream>
Config::Config() { Config::Config() {
verbose = false; verbose = false;
daemon = true; daemon = true;
@ -9,6 +17,7 @@ Config::Config () {
updateFeeds = false; updateFeeds = false;
} }
Config::Config(Config* cfg) { Config::Config(Config* cfg) {
verbose = cfg->verbose; verbose = cfg->verbose;
daemon = cfg->daemon; daemon = cfg->daemon;
@ -18,6 +27,7 @@ Config::Config ( Config* cfg ) {
maxDate = cfg->maxDate; maxDate = cfg->maxDate;
} }
// !! handle file status // !! handle file status
void void
Config::Load() Config::Load()
@ -36,10 +46,12 @@ Config::Load ()
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;
} }
// !! handle file status // !! handle file status
void void
Config::Save () Config::Save ()
@ -59,7 +71,8 @@ Config::Save ()
BMessage storage; BMessage storage;
BString filename = BString(configDir).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("outDir", outDir.String()); storage.AddString("outDir", outDir.String());

View File

@ -1,15 +1,24 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
#include <DateTime.h> #include <DateTime.h>
#include <String.h> #include <String.h>
#include <StorageKit.h> #include <StorageKit.h>
class Config { class Config {
public: public:
Config(); Config();
Config(Config*); Config(Config*);
void Load();
void Save();
bool verbose; bool verbose;
bool daemon; bool daemon;
BString outDir; BString outDir;
@ -23,9 +32,8 @@ public:
bool will_save; bool will_save;
bool updateFeeds; bool updateFeeds;
void Load ( );
void Save ( );
}; };
#endif #endif

View File

@ -1,11 +1,19 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "Entry.h"
#include <StorageKit.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <tinyxml2.h>
#include <StorageKit.h>
#include "Config.h" #include "Config.h"
#include "Entry.h"
#include "Util.h" #include "Util.h"
Entry::Entry(BString outputPath) Entry::Entry(BString outputPath)
{ {
title = BString(""); title = BString("");
@ -16,6 +24,7 @@ Entry::Entry ( BString outputPath )
outputDir = outputPath; outputDir = outputPath;
} }
bool bool
Entry::Filetize(bool onlyIfNew = false) Entry::Filetize(bool onlyIfNew = false)
{ {
@ -26,8 +35,8 @@ Entry::Filetize ( bool onlyIfNew = false )
dir->CreateFile(title.String(), file); dir->CreateFile(title.String(), file);
BString betype = BString("text/x-feed-entry"); BString betype = BString("text/x-feed-entry");
file->WriteAttr( "BEOS:TYPE", B_MIME_STRING_TYPE, 0, file->WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, betype.String(),
betype.String(), betype.CountChars() + 1 ); betype.CountChars() + 1);
file->WriteAttr("FEED:name", B_STRING_TYPE, 0, file->WriteAttr("FEED:name", B_STRING_TYPE, 0,
title.String(), title.CountChars()); title.String(), title.CountChars());
@ -35,62 +44,99 @@ Entry::Filetize ( bool onlyIfNew = false )
description.String(), description.CountChars()); description.String(), description.CountChars());
file->WriteAttr("FEED:source", B_STRING_TYPE, 0, file->WriteAttr("FEED:source", B_STRING_TYPE, 0,
feedTitle.String(), feedTitle.CountChars()); feedTitle.String(), feedTitle.CountChars());
file->WriteAttr( "META:url", B_STRING_TYPE, 0, file->WriteAttr("META:url", B_STRING_TYPE, 0, postUrl.String(),
postUrl.String(), postUrl.CountChars() ); postUrl.CountChars());
if (date != NULL) { if (date != NULL) {
file->WriteAttr( "FEED:when", B_TIME_TYPE, 0, file->WriteAttr("FEED:when", B_TIME_TYPE, 0, &tt_date, sizeof(time_t));
&tt_date, sizeof(time_t) );
} }
file->Write(content.String(), content.Length()); file->Write(content.String(), content.Length());
return false; return false;
} }
bool Entry::SetTitle ( const char* titleStr ) {
if ( titleStr != NULL ) title = BString( titleStr ); bool
else return false; Entry::SetTitle(const char* titleStr) {
return true; if (titleStr != NULL)
} title = BString(titleStr);
bool Entry::SetTitle ( tinyxml2::XMLElement* elem ) {
if ( elem != NULL ) return SetTitle( elem->GetText() );
return false;
}
bool Entry::SetDesc ( const char* descStr ) {
if ( descStr != NULL ) description = BString( descStr );
else return false;
return true;
}
bool Entry::SetDesc ( tinyxml2::XMLElement* elem ) {
if ( elem != NULL ) return SetDesc( elem->GetText() );
return false;
}
bool Entry::SetFeedTitle ( BString titleStr ) {
if ( titleStr != NULL ) feedTitle = titleStr;
else return false; else return false;
return true; return true;
} }
bool Entry::SetContent ( const char* contentStr ) {
if ( contentStr != NULL ) content = BString( contentStr ); bool
else return false; Entry::SetTitle(tinyxml2::XMLElement* elem) {
return true; if (elem != NULL)
} return SetTitle(elem->GetText());
bool Entry::SetContent ( tinyxml2::XMLElement* elem ) {
if ( elem != NULL ) return SetContent( elem->GetText() );
return false; return false;
} }
bool Entry::SetPostUrl ( const char* urlStr ) {
if ( urlStr != NULL ) postUrl = BString( urlStr ); bool
Entry::SetDesc(const char* descStr) {
if (descStr != NULL)
description = BString(descStr);
else return false; else return false;
return true; return true;
} }
bool Entry::SetPostUrl ( tinyxml2::XMLElement* elem ) {
if ( elem != NULL ) return SetPostUrl( elem->GetText() );
bool
Entry::SetDesc(tinyxml2::XMLElement* elem) {
if (elem != NULL)
return SetDesc(elem->GetText());
return false; return false;
} }
bool Entry::SetDate ( const char* dateStr ) {
bool
Entry::SetFeedTitle(BString titleStr) {
if (titleStr != NULL)
feedTitle = titleStr;
else return false;
return true;
}
bool
Entry::SetContent(const char* contentStr)
{
if (contentStr != NULL)
content = BString(contentStr);
else return false;
return true;
}
bool
Entry::SetContent(tinyxml2::XMLElement* elem)
{
if (elem != NULL)
return SetContent(elem->GetText());
return false;
}
bool
Entry::SetPostUrl(const char* urlStr) {
if (urlStr != NULL)
postUrl = BString(urlStr);
else return false;
return true;
}
bool
Entry::SetPostUrl(tinyxml2::XMLElement* elem) {
if (elem != NULL)
return SetPostUrl(elem->GetText());
return false;
}
bool
Entry::SetDate(const char* dateStr) {
if (dateStr == NULL) if (dateStr == NULL)
return false; return false;
BDateTime newDate = feedDateToBDate(dateStr); BDateTime newDate = feedDateToBDate(dateStr);
@ -99,7 +145,13 @@ bool Entry::SetDate ( const char* dateStr ) {
date = newDate; date = newDate;
return true; return true;
} }
bool Entry::SetDate ( tinyxml2::XMLElement* elem ) {
if ( elem != NULL ) return SetDate( elem->GetText() );
bool
Entry::SetDate(tinyxml2::XMLElement* elem) {
if (elem != NULL)
return SetDate(elem->GetText());
return false; return false;
} }

View File

@ -1,21 +1,23 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef ENTRY_H #ifndef ENTRY_H
#define ENTRY_H #define ENTRY_H
#include <DateTime.h> #include <DateTime.h>
#include <String.h>
#include <List.h> #include <List.h>
#include <String.h>
#include <Url.h> #include <Url.h>
#include <tinyxml2.h>
#include "Config.h" #include "Config.h"
class Entry { class Entry {
public: public:
BString title;
BString description;
BString feedTitle;
BDateTime date;
BString postUrl;
BString content;
BString outputDir;
Entry(BString); Entry(BString);
@ -32,6 +34,16 @@ public:
bool SetPostUrl(tinyxml2::XMLElement*); bool SetPostUrl(tinyxml2::XMLElement*);
bool SetDate(const char*); bool SetDate(const char*);
bool SetDate(tinyxml2::XMLElement*); bool SetDate(tinyxml2::XMLElement*);
BString title;
BString description;
BString feedTitle;
BDateTime date;
BString postUrl;
BString content;
BString outputDir;
}; };
#endif #endif

View File

@ -1,9 +1,17 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "Feed.h"
#include <tinyxml2.h> #include <tinyxml2.h>
#include "App.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"
Feed::Feed(BString path) Feed::Feed(BString path)
{ {
@ -17,6 +25,7 @@ Feed::Feed ( BString path )
SetCachePath(path); SetCachePath(path);
} }
Feed::Feed() Feed::Feed()
{ {
title = BString(""); title = BString("");
@ -25,25 +34,23 @@ Feed::Feed ( )
xmlUrl = BString(""); xmlUrl = BString("");
} }
// ----------------------------------------------------------------------------
void void
Feed::Parse() Feed::Parse()
{ {
BFile* feedFile = new BFile(GetCachePath().String(), B_READ_ONLY); BFile* feedFile = new BFile(GetCachePath().String(), B_READ_ONLY);
time_t tt_lastDate = 0;
BDateTime attrLastDate = BDateTime(); BDateTime attrLastDate = BDateTime();
time_t tt_lastDate = 0;
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 && ((App*)be_app)->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;
} }
} }
// -------------------------------------
// -------------------------------------
// Download a remote feed's XML to the cache path. // Download a remote feed's XML to the cache path.
BString BString
@ -74,7 +81,6 @@ Feed::FetchRemoteFeed ( )
return GetCachePath(); return GetCachePath();
} }
// ----------------------------------------------------------------------------
// return whether or not the feed's given URI/path is remote. // return whether or not the feed's given URI/path is remote.
bool bool
@ -83,6 +89,7 @@ Feed::IsRemote ( )
return isRemotePath(inputPath); return isRemotePath(inputPath);
} }
// return whether or not the feed seems to have been updated // return whether or not the feed seems to have been updated
bool bool
Feed::IsUpdated () Feed::IsUpdated ()
@ -90,6 +97,7 @@ Feed::IsUpdated ( )
return updated; return updated;
} }
// return whether or not feed is RSS // return whether or not feed is RSS
bool bool
Feed::IsRss () Feed::IsRss ()
@ -103,6 +111,7 @@ Feed::IsRss ( )
return false; return false;
} }
// return whether or not feed is Atom // return whether or not feed is Atom
bool bool
Feed::IsAtom () Feed::IsAtom ()
@ -115,7 +124,6 @@ Feed::IsAtom ( )
return false; return false;
} }
// ----------------------------------------------------------------------------
// ensure the feed XML is available at the cache path. // ensure the feed XML is available at the cache path.
// if necessary, download it. // if necessary, download it.
@ -126,6 +134,7 @@ Feed::EnsureCached ( )
FetchRemoteFeed(); FetchRemoteFeed();
} }
// Return the 'cachePath' (location of XML file locally) // Return the 'cachePath' (location of XML file locally)
BString BString
Feed::GetCachePath () Feed::GetCachePath ()
@ -135,6 +144,7 @@ Feed::GetCachePath ( )
return cachePath; return cachePath;
} }
// Select a 'cachePath' (location of XML file locally) // Select a 'cachePath' (location of XML file locally)
// For remote files, a cache file is created in ~/config/cache/Pogger/ by default // For remote files, a cache file is created in ~/config/cache/Pogger/ by default
// For local files, the same local file is used. // For local files, the same local file is used.
@ -160,7 +170,6 @@ Feed::SetCachePath ( BString givenPath )
return filename; return filename;
} }
// ----------------------------------------------------------------------------
// count the amount of siblings to an element of given type name // count the amount of siblings to an element of given type name
int int
@ -174,7 +183,6 @@ Feed::xmlCountSiblings ( tinyxml2::XMLElement* xsibling, const char* sibling_nam
return count; return count;
} }
// ----------------------------------------------------------------------------
// add the given entry to the feed, if appropriate // add the given entry to the feed, if appropriate
bool bool
@ -190,44 +198,98 @@ Feed::AddEntry ( Entry* newEntry )
entries.AddItem(newEntry); entries.AddItem(newEntry);
return true; return true;
} }
BList Feed::GetEntries ( ) { return entries; }
bool Feed::SetTitle ( const char* titleStr ) {
if ( titleStr != NULL ) title = BString( titleStr ); BList
Feed::GetEntries()
{
return entries;
}
bool
Feed::SetTitle(const char* titleStr)
{
if (titleStr != NULL)
title = BString(titleStr);
else return false; else return false;
return true; return true;
} }
bool Feed::SetTitle ( tinyxml2::XMLElement* elem ) {
if ( elem != NULL ) return SetTitle( elem->GetText() );
bool
Feed::SetTitle(tinyxml2::XMLElement* elem)
{
if (elem != NULL)
return SetTitle(elem->GetText());
else return false; else return false;
} }
BString Feed::GetTitle ( ) { return title; }
bool Feed::SetDesc ( const char* descStr ) {
if ( descStr != NULL ) description = BString( descStr ); BString
Feed::GetTitle()
{
return title;
}
bool
Feed::SetDesc(const char* descStr)
{
if (descStr != NULL)
description = BString(descStr);
else return false; else return false;
return true; return true;
} }
bool Feed::SetDesc ( tinyxml2::XMLElement* elem ) {
if ( elem != NULL ) return SetDesc( elem->GetText() );
bool
Feed::SetDesc(tinyxml2::XMLElement* elem)
{
if (elem != NULL)
return SetDesc(elem->GetText());
else return false; else return false;
} }
BString Feed::GetDesc ( ) { return description; }
BString
Feed::GetDesc()
{
return description;
}
// set a feed's «home URL» // set a feed's «home URL»
bool Feed::SetHomeUrl ( const char* homepageStr ) { bool
if ( homepageStr != NULL ) homeUrl = BString( homepageStr ); Feed::SetHomeUrl(const char* homepageStr)
{
if (homepageStr != NULL)
homeUrl = BString(homepageStr);
else return false; else return false;
return true; return true;
} }
bool Feed::SetHomeUrl ( tinyxml2::XMLElement* elem ) {
if ( elem != NULL ) return SetHomeUrl( elem->GetText() );
bool
Feed::SetHomeUrl(tinyxml2::XMLElement* elem)
{
if (elem != NULL)
return SetHomeUrl(elem->GetText());
else return false; else return false;
} }
BString Feed::GetHomeUrl ( ) { return homeUrl; }
BString
Feed::GetHomeUrl()
{
return homeUrl;
}
// set the update time for a feed // set the update time for a feed
bool Feed::SetDate ( const char* dateCStr ) { bool
Feed::SetDate(const char* dateCStr)
{
if (dateCStr == NULL) if (dateCStr == NULL)
return false; return false;
BDateTime newDate = feedDateToBDate(dateCStr); BDateTime newDate = feedDateToBDate(dateCStr);
@ -236,9 +298,21 @@ bool Feed::SetDate ( const char* dateCStr ) {
date = newDate; date = newDate;
return true; return true;
} }
bool Feed::SetDate ( tinyxml2::XMLElement* elem ) {
if ( elem != NULL ) return SetDate( elem->GetText() );
bool
Feed::SetDate(tinyxml2::XMLElement* elem)
{
if (elem != NULL)
return SetDate(elem->GetText());
else return false; else return false;
} }
BDateTime Feed::GetDate ( ) { return date; }
BDateTime
Feed::GetDate()
{
return date;
}

View File

@ -1,13 +1,22 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef FEED_H #ifndef FEED_H
#define FEED_H #define FEED_H
#include <tinyxml2.h> #include <tinyxml2.h>
#include <DateTime.h>
#include <String.h>
#include <List.h>
#include <Url.h>
#include "Entry.h" #include "Entry.h"
class BDateTime;
class BString;
class BList;
class BUrl;
class Feed { class Feed {
public: public:
Feed(BString); Feed(BString);
@ -57,7 +66,8 @@ protected:
BList entries; BList entries;
bool fetched; bool fetched;
bool updated; bool updated;
}; };
#endif #endif

View File

@ -1,15 +1,24 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "Invocation.h"
#include <StorageKit.h> #include <StorageKit.h>
#include <String.h> #include <String.h>
#include <getopt.h> #include <getopt.h>
#include "AtomFeed.h"
#include "RssFeed.h"
#include "Feed.h"
#include "Entry.h"
#include "Mimetypes.h"
#include "Config.h"
#include "Util.h"
#include "App.h" #include "App.h"
#include "Invocation.h" #include "AtomFeed.h"
#include "Config.h"
#include "Entry.h"
#include "Feed.h"
#include "Mimetypes.h"
#include "RssFeed.h"
#include "Util.h"
int int
usage() usage()
@ -18,6 +27,7 @@ usage ( )
return 2; return 2;
} }
int int
invocation(int argc, char** argv) invocation(int argc, char** argv)
{ {
@ -97,7 +107,6 @@ invocation ( int argc, char** argv )
} }
} }
// -------------------------------------
void void
freeargInvocation(int argc, char** argv, int optind) freeargInvocation(int argc, char** argv, int optind)
@ -114,7 +123,6 @@ freeargInvocation ( int argc, char** argv, int optind )
} }
} }
// ----------------------------------------------------------------------------
bool bool
processEntry(void* entry) processEntry(void* entry)
@ -124,6 +132,7 @@ processEntry ( void* entry )
return false; return false;
} }
bool bool
processFeed(void* feedArg) processFeed(void* feedArg)
{ {
@ -131,7 +140,8 @@ processFeed ( void* feedArg )
Feed* testFeed = new Feed(*(feedStr)); Feed* testFeed = new Feed(*(feedStr));
BList entries; BList entries;
if ( testFeed->IsUpdated() == false && ((App*)be_app)->cfg->updateFeeds == true ) if (testFeed->IsUpdated() == false
&& ((App*)be_app)->cfg->updateFeeds == true)
return false; return false;
if (testFeed->IsAtom()) { if (testFeed->IsAtom()) {
@ -150,3 +160,5 @@ processFeed ( void* feedArg )
entries.DoForEach(&processEntry); entries.DoForEach(&processEntry);
return false; return false;
} }

View File

@ -1,7 +1,10 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef INVOCATION_H #ifndef INVOCATION_H
#define INVOCATION_H #define INVOCATION_H
#include <StorageKit.h>
int usage ( ); int usage ( );
int invocation ( int, char** ); int invocation ( int, char** );
@ -9,6 +12,6 @@ void freeargInvocation ( int, char**, int );
bool processItem ( void* ); bool processItem ( void* );
bool processFeed ( void* ); bool processFeed ( void* );
// ----------------------------------------------------------------------------
#endif #endif

View File

@ -1,10 +1,15 @@
// borrowed significantly (addAttribute) from mailserver. thanks! <3 /*
#include <iostream> * Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "Mimetypes.h"
#include <Application.h> #include <Application.h>
#include <DateTime.h> #include <DateTime.h>
#include <Message.h> #include <Message.h>
#include <MimeType.h> #include <MimeType.h>
#include "Mimetypes.h"
// install the Feed Entry mimetype, if need be // install the Feed Entry mimetype, if need be
bool bool
@ -12,9 +17,9 @@ feedMimeType ( )
{ {
BMessage info; BMessage info;
BMimeType mime("text/x-feed-entry"); BMimeType mime("text/x-feed-entry");
if ( mime.IsInstalled() ) return true; if (mime.IsInstalled())
return true;
std::cout << "NOT INSTALLED";
mime.GetAttrInfo(&info); mime.GetAttrInfo(&info);
mime.SetShortDescription("Feed Entry"); mime.SetShortDescription("Feed Entry");
@ -29,12 +34,12 @@ feedMimeType ( )
return mime.SetAttrInfo(&info); return mime.SetAttrInfo(&info);
} }
// -------------------------------------
// add the given attribute to a BMessage for use as attr info // add the given attribute to a BMessage for use as attr info
// borrowed from mailserver (thanks!)
static void static void
addAttribute addAttribute(BMessage& msg, const char* name, const char* publicName,
( BMessage& msg, const char* name, const char* publicName, int32 type, int32 width ) int32 type, int32 width)
{ {
msg.AddString("attr:name", name); msg.AddString("attr:name", name);
msg.AddString("attr:public_name", publicName); msg.AddString("attr:public_name", publicName);
@ -45,3 +50,5 @@ addAttribute
msg.AddBool("attr:viewable", true); msg.AddBool("attr:viewable", true);
msg.AddBool("attr:editable", true); msg.AddBool("attr:editable", true);
} }

View File

@ -1,13 +1,22 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef MIME_H #ifndef MIME_H
#define MIME_H #define MIME_H
#include <Message.h> #include <SupportDefs.h>
#include <String.h> #include <TypeConstants.h>
class BMessage;
bool feedMimeType(); bool feedMimeType();
static void addAttribute static void addAttribute(BMessage&, const char*, const char*,
( BMessage&, const char*, const char*, int32 type = B_STRING_TYPE, int32 width = 200); int32 type = B_STRING_TYPE, int32 width = 200);
#endif #endif

View File

@ -1,9 +1,15 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "ProtocolListener.h"
#include <Url.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <UrlProtocolListener.h>
#include <Url.h>
#include <boost/uuid/detail/sha1.hpp>
#include "ProtocolListener.h"
ProtocolListener::ProtocolListener(bool traceLogging) ProtocolListener::ProtocolListener(bool traceLogging)
: :
@ -11,11 +17,14 @@ ProtocolListener::ProtocolListener ( bool traceLogging )
fTraceLogging(traceLogging) fTraceLogging(traceLogging)
{} {}
ProtocolListener::~ProtocolListener() ProtocolListener::~ProtocolListener()
{} {}
void void
ProtocolListener::DataReceived ( BUrlRequest* caller, const char* data, off_t position, ssize_t size ) ProtocolListener::DataReceived(BUrlRequest* caller, const char* data,
off_t position, ssize_t size)
{ {
if (fDownloadIO != NULL) if (fDownloadIO != NULL)
fDownloadIO->Write(data, size); fDownloadIO->Write(data, size);
@ -23,30 +32,35 @@ ProtocolListener::DataReceived ( BUrlRequest* caller, const char* data, off_t po
fSha1->process_bytes(data, size); fSha1->process_bytes(data, size);
} }
void void
ProtocolListener::SetDownloadIO(BDataIO* downloadIO) ProtocolListener::SetDownloadIO(BDataIO* downloadIO)
{ {
fDownloadIO = downloadIO; fDownloadIO = downloadIO;
} }
BDataIO* BDataIO*
ProtocolListener::GetDownloadIO() ProtocolListener::GetDownloadIO()
{ {
return fDownloadIO; return fDownloadIO;
} }
void void
ProtocolListener::SetSha1(boost::uuids::detail::sha1* sha1) ProtocolListener::SetSha1(boost::uuids::detail::sha1* sha1)
{ {
fSha1 = sha1; fSha1 = sha1;
} }
boost::uuids::detail::sha1* boost::uuids::detail::sha1*
ProtocolListener::GetSha1() ProtocolListener::GetSha1()
{ {
return fSha1; return fSha1;
} }
BString BString
ProtocolListener::GetHash() ProtocolListener::GetHash()
{ {
@ -61,3 +75,4 @@ ProtocolListener::GetHash ( )
return BString(hashStr.str().c_str()); return BString(hashStr.str().c_str());
} }

View File

@ -1,16 +1,21 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef PROTOCOL_LISTENER_H #ifndef PROTOCOL_LISTENER_H
#define PROTOCOL_LISTENER_H #define PROTOCOL_LISTENER_H
#include <UrlProtocolListener.h>
#include <Url.h>
#include <boost/uuid/detail/sha1.hpp> #include <boost/uuid/detail/sha1.hpp>
#include <UrlProtocolListener.h>
class ProtocolListener : public BUrlProtocolListener class ProtocolListener : public BUrlProtocolListener
{ {
public: public:
ProtocolListener(bool); 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);
void SetDownloadIO(BDataIO*); void SetDownloadIO(BDataIO*);
@ -26,4 +31,6 @@ private:
bool fTraceLogging; bool fTraceLogging;
}; };
#endif #endif

View File

@ -1,9 +1,15 @@
#include <tinyxml2.h> /*
#include "Entry.h" * Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "RssFeed.h"
#include "App.h" #include "App.h"
#include "Config.h" #include "Config.h"
#include "Entry.h"
#include "Util.h" #include "Util.h"
#include "RssFeed.h"
RssFeed::RssFeed() RssFeed::RssFeed()
{ {
@ -14,10 +20,10 @@ RssFeed::RssFeed ( )
outputDir = ((App*)be_app)->cfg->outDir; outputDir = ((App*)be_app)->cfg->outDir;
} }
RssFeed::RssFeed(Feed* feed) : RssFeed::RssFeed() RssFeed::RssFeed(Feed* feed) : RssFeed::RssFeed()
{ SetCachePath(feed->GetCachePath()); } { SetCachePath(feed->GetCachePath()); }
// ----------------------------------------------------------------------------
void void
RssFeed::Parse() RssFeed::Parse()
@ -38,7 +44,6 @@ RssFeed::Parse ( )
feedFile->WriteAttr("LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t)); feedFile->WriteAttr("LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t));
} }
// -------------------------------------
void void
RssFeed::RootParse(tinyxml2::XMLElement* xchan) RssFeed::RootParse(tinyxml2::XMLElement* xchan)
@ -52,6 +57,7 @@ RssFeed::RootParse ( tinyxml2::XMLElement* xchan )
printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String()); printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String());
} }
void void
RssFeed::EntryParse(tinyxml2::XMLElement* xitem) RssFeed::EntryParse(tinyxml2::XMLElement* xitem)
{ {
@ -71,6 +77,7 @@ RssFeed::EntryParse ( tinyxml2::XMLElement* xitem )
AddEntry(newEntry); AddEntry(newEntry);
} }
void void
RssFeed::ParseEntries(tinyxml2::XMLElement* xchan) RssFeed::ParseEntries(tinyxml2::XMLElement* xchan)
{ {
@ -89,3 +96,5 @@ RssFeed::ParseEntries ( tinyxml2::XMLElement* xchan )
xitem = xitem->NextSiblingElement("item"); xitem = xitem->NextSiblingElement("item");
} }
} }

View File

@ -1,13 +1,15 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef RSS_FEED_H #ifndef RSS_FEED_H
#define RSS_FEED_H #define RSS_FEED_H
#include <tinyxml2.h> #include <tinyxml2.h>
#include <DateTime.h>
#include <String.h>
#include <List.h>
#include <Url.h>
#include "Feed.h" #include "Feed.h"
class RssFeed: public Feed { class RssFeed: public Feed {
public: public:
RssFeed(); RssFeed();
@ -19,4 +21,6 @@ public:
void ParseEntries(tinyxml2::XMLElement*); void ParseEntries(tinyxml2::XMLElement*);
}; };
#endif #endif

View File

@ -1,37 +1,45 @@
#include <iostream> /*
#include <sstream> * Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
#include <locale> * All rights reserved. Distributed under the terms of the MIT license.
#include <iomanip> */
#include <DateTime.h>
#include <UrlProtocolRoster.h>
#include <Url.h>
#include <UrlRequest.h>
#include <boost/uuid/detail/sha1.hpp>
#include "ProtocolListener.h"
#include "Util.h" #include "Util.h"
// ---------------------------------------------------------------------------- #include <Url.h>
#include <UrlProtocolRoster.h>
#include <UrlRequest.h>
#include <boost/uuid/detail/sha1.hpp>
#include <iostream>
#include <iomanip>
#include "ProtocolListener.h"
BDateTime BDateTime
feedDateToBDate(const char* dateCStr) feedDateToBDate(const char* dateCStr)
{ {
BDateTime date = dateRfc822ToBDate(dateCStr); BDateTime date = dateRfc822ToBDate(dateCStr);
if ( date == NULL ) date = dateRfc3339ToBDate( dateCStr ); if (date == NULL)
date = dateRfc3339ToBDate(dateCStr);
return date; return date;
} }
BDateTime BDateTime
dateRfc3339ToBDate(const char* dateCStr) dateRfc3339ToBDate(const char* dateCStr)
{ {
return stringDateToBDate(dateCStr, "%Y-%m-%dT%H:%M:%S"); return stringDateToBDate(dateCStr, "%Y-%m-%dT%H:%M:%S");
} }
BDateTime BDateTime
dateRfc822ToBDate(const char* dateCStr) dateRfc822ToBDate(const char* dateCStr)
{ {
return stringDateToBDate(dateCStr, "%a, %d %b %Y %H:%M:%S"); return stringDateToBDate(dateCStr, "%a, %d %b %Y %H:%M:%S");
} }
BDateTime BDateTime
stringDateToBDate(const char* dateCStr, const char* templateCStr) stringDateToBDate(const char* dateCStr, const char* templateCStr)
{ {
@ -40,13 +48,13 @@ stringDateToBDate ( const char* dateCStr, const char* templateCStr )
if (dateStream >> std::get_time(&time, templateCStr)) { if (dateStream >> std::get_time(&time, templateCStr)) {
BTime newTime = BTime(time.tm_hour, time.tm_min, time.tm_sec, 0); BTime newTime = BTime(time.tm_hour, time.tm_min, time.tm_sec, 0);
BDate newDate = BDate( time.tm_year + 1900, time.tm_mon + 1, time.tm_mday ); BDate newDate = BDate(time.tm_year + 1900, time.tm_mon + 1,
time.tm_mday);
return BDateTime(newDate, newTime); return BDateTime(newDate, newTime);
} }
return NULL; return NULL;
} }
// ----------------------------------------------------------------------------
BString BString
dateTo3339String(BDateTime dt) dateTo3339String(BDateTime dt)
@ -59,7 +67,6 @@ dateTo3339String ( BDateTime dt )
return BString(buffer); return BString(buffer);
} }
// ----------------------------------------------------------------------------
bool bool
withinDateRange(BDateTime minDate, BDateTime nowDate, BDateTime maxDate) withinDateRange(BDateTime minDate, BDateTime nowDate, BDateTime maxDate)
@ -73,7 +80,6 @@ withinDateRange ( BDateTime minDate, BDateTime nowDate, BDateTime maxDate )
return true; return true;
} }
// ----------------------------------------------------------------------------
// return whether or not the given path is remote // return whether or not the given path is remote
bool bool
@ -81,12 +87,12 @@ isRemotePath ( BString path ) {
BUrl givenUrl = BUrl(path); BUrl givenUrl = BUrl(path);
BString protocol = givenUrl.Protocol().String(); BString protocol = givenUrl.Protocol().String();
if ( protocol == NULL || protocol == BString("file") || givenUrl.UrlString() == NULL ) if (protocol == NULL || protocol == BString("file")
|| givenUrl.UrlString() == NULL)
return false; return false;
return true; return true;
} }
// ----------------------------------------------------------------------------
int32 int32
webFetch(BUrl url, BDataIO* reply) webFetch(BUrl url, BDataIO* reply)
@ -115,3 +121,5 @@ webFetch ( BUrl url, BDataIO* reply, BString* hash )
return request->Status(); return request->Status();
return 200; return 200;
} }

View File

@ -1,10 +1,17 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#ifndef UTIL_H #ifndef UTIL_H
#define UTIL_H #define UTIL_H
#include <DateTime.h> #include <DateTime.h>
#include <Url.h>
#include "ProtocolListener.h" #include "ProtocolListener.h"
class BUrl;
BDateTime feedDateToBDate(const char*); BDateTime feedDateToBDate(const char*);
BDateTime dateRfc3339ToBDate(const char*); BDateTime dateRfc3339ToBDate(const char*);
BDateTime dateRfc822ToBDate(const char*); BDateTime dateRfc822ToBDate(const char*);
@ -19,4 +26,6 @@ bool isRemotePath ( BString );
int32 webFetch(BUrl, BDataIO*, BString*); int32 webFetch(BUrl, BDataIO*, BString*);
int32 webFetch(BUrl, BDataIO*); int32 webFetch(BUrl, BDataIO*);
#endif #endif