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.
# Also note that spaces in folder names do not work well with this Makefile.
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/AtomFeed.cpp, \
src/Config.cpp, \
src/Entry.cpp, \
src/Feed.cpp, \
src/FeedView.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
# used.

View File

@ -112,5 +112,5 @@ Sry bby, i'm trying <3
BORING INFO
--------------------------------------------------
Pogger is under the MIT license.
https://git.xwx.moe/pogger.git
https://git.feneas.org/detruota/pogger
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 <String.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 "MainWindow.h"
#include "Entry.h"
#include "Feed.h"
#include "Invocation.h"
#include "MainWindow.h"
#include "Mimetypes.h"
#include "RssFeed.h"
#include "Util.h"
int
@ -36,7 +44,6 @@ main ( int argc, char** argv )
return 0;
}
// -------------------------------------
void
cliStart(int argc, char** argv)
@ -45,16 +52,14 @@ cliStart ( int argc, char** argv )
((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();
mainWin->Show();
}
// ----------------------------------------------------------------------------
const char* configPath = "/boot/home/config/settings/Pogger/";
BString usageMsg =
"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 <Application.h>
#include "Config.h"
class Config;
class App : public BApplication
@ -13,14 +20,14 @@ public:
Config* cfg;
};
// ----------------------------------------------------------------------------
int main ( int, char** );
void cliStart ( int, char** );
// ----------------------------------------------------------------------------
extern const char* configPath;
extern BString usageMsg;
#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 "Entry.h"
#include "App.h"
#include "Config.h"
#include "Entry.h"
#include "Util.h"
#include "AtomFeed.h"
AtomFeed::AtomFeed()
{
@ -15,10 +23,13 @@ AtomFeed::AtomFeed ( )
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
AtomFeed::Parse ()
@ -36,9 +47,11 @@ AtomFeed::Parse ( )
BFile* feedFile = new BFile(GetCachePath().String(), B_READ_WRITE);
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
AtomFeed::RootParse(tinyxml2::XMLElement* xfeed)
{
@ -53,18 +66,24 @@ AtomFeed::RootParse( tinyxml2::XMLElement* xfeed )
SetDesc( xfeed->FirstChildElement("description"));
set = SetDate(xfeed->FirstChildElement("updated"));
if ( !set ) set = SetDate( xfeed->FirstChildElement("published") );
if ( !set && xentry ) set = SetDate( xentry->FirstChildElement("updated") );
if ( !set && xentry ) set = SetDate( xentry->FirstChildElement("published") );
if (!set)
set = SetDate(xfeed->FirstChildElement("published"));
if (!set && xentry)
set = SetDate(xentry->FirstChildElement("updated"));
if (!set && xentry)
set = SetDate(xentry->FirstChildElement("published"));
set = SetHomeUrl(xlink->Attribute("href"));
if ( !set && xauthor ) set = SetHomeUrl( xauthor->FirstChildElement("uri") );
if ( !set && xauthlink ) set = SetHomeUrl( xauthlink->Attribute( "href" ) );
if (!set && xauthor)
set = SetHomeUrl(xauthor->FirstChildElement("uri"));
if (!set && xauthlink)
set = SetHomeUrl(xauthlink->Attribute("href"));
if (((App*)be_app)->cfg->verbose)
printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String());
}
void
AtomFeed::EntryParse(tinyxml2::XMLElement* xentry)
{
@ -81,11 +100,14 @@ AtomFeed::EntryParse ( tinyxml2::XMLElement* xentry )
bool set = false;
set = newEntry->SetDesc(xentry->FirstChildElement("summary"));
if ( !set ) set = newEntry->SetDesc( xentry->FirstChildElement("description"));
if ( !set && xmedia ) set = newEntry->SetDesc( xmedia->FirstChildElement("media:description"));
if (!set)
set = newEntry->SetDesc(xentry->FirstChildElement("description"));
if (!set && xmedia)
set = newEntry->SetDesc(xmedia->FirstChildElement("media:description"));
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)
lastDate = newEntry->date;
@ -98,6 +120,7 @@ AtomFeed::EntryParse ( tinyxml2::XMLElement* xentry )
AddEntry(newEntry);
}
void
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
#define ATOM_FEED_H
#include <tinyxml2.h>
#include <DateTime.h>
#include <String.h>
#include <List.h>
#include <Url.h>
#include "Config.h"
#include "Feed.h"
class AtomFeed: public Feed {
public:
AtomFeed();
@ -20,4 +22,6 @@ public:
void ParseEntries(tinyxml2::XMLElement*);
};
#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 <String.h>
#include <iostream>
Config::Config() {
verbose = false;
daemon = true;
@ -9,6 +17,7 @@ Config::Config () {
updateFeeds = false;
}
Config::Config(Config* cfg) {
verbose = cfg->verbose;
daemon = cfg->daemon;
@ -18,6 +27,7 @@ Config::Config ( Config* cfg ) {
maxDate = cfg->maxDate;
}
// !! handle file status
void
Config::Load()
@ -36,10 +46,12 @@ Config::Load ()
if (outDir == NULL)
outDir = BString(storage.GetString("outDir", "/boot/home/feeds/"));
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;
}
// !! handle file status
void
Config::Save ()
@ -59,7 +71,8 @@ Config::Save ()
BMessage storage;
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();
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
#define CONFIG_H
#include <DateTime.h>
#include <String.h>
#include <StorageKit.h>
class Config {
public:
Config();
Config(Config*);
void Load();
void Save();
bool verbose;
bool daemon;
BString outDir;
@ -23,9 +32,8 @@ public:
bool will_save;
bool updateFeeds;
void Load ( );
void Save ( );
};
#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 <fstream>
#include <tinyxml2.h>
#include <StorageKit.h>
#include "Config.h"
#include "Entry.h"
#include "Util.h"
Entry::Entry(BString outputPath)
{
title = BString("");
@ -16,6 +24,7 @@ Entry::Entry ( BString outputPath )
outputDir = outputPath;
}
bool
Entry::Filetize(bool onlyIfNew = false)
{
@ -26,8 +35,8 @@ Entry::Filetize ( bool onlyIfNew = false )
dir->CreateFile(title.String(), file);
BString betype = BString("text/x-feed-entry");
file->WriteAttr( "BEOS:TYPE", B_MIME_STRING_TYPE, 0,
betype.String(), betype.CountChars() + 1 );
file->WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, betype.String(),
betype.CountChars() + 1);
file->WriteAttr("FEED:name", B_STRING_TYPE, 0,
title.String(), title.CountChars());
@ -35,62 +44,99 @@ Entry::Filetize ( bool onlyIfNew = false )
description.String(), description.CountChars());
file->WriteAttr("FEED:source", B_STRING_TYPE, 0,
feedTitle.String(), feedTitle.CountChars());
file->WriteAttr( "META:url", B_STRING_TYPE, 0,
postUrl.String(), postUrl.CountChars() );
file->WriteAttr("META:url", B_STRING_TYPE, 0, postUrl.String(),
postUrl.CountChars());
if (date != NULL) {
file->WriteAttr( "FEED:when", B_TIME_TYPE, 0,
&tt_date, sizeof(time_t) );
file->WriteAttr("FEED:when", B_TIME_TYPE, 0, &tt_date, sizeof(time_t));
}
file->Write(content.String(), content.Length());
return false;
}
bool Entry::SetTitle ( const char* titleStr ) {
if ( titleStr != NULL ) title = BString( titleStr );
else return false;
return true;
}
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;
bool
Entry::SetTitle(const char* titleStr) {
if (titleStr != NULL)
title = BString(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() );
bool
Entry::SetTitle(tinyxml2::XMLElement* elem) {
if (elem != NULL)
return SetTitle(elem->GetText());
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;
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;
}
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)
return false;
BDateTime newDate = feedDateToBDate(dateStr);
@ -99,7 +145,13 @@ bool Entry::SetDate ( const char* dateStr ) {
date = newDate;
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;
}

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
#define ENTRY_H
#include <DateTime.h>
#include <String.h>
#include <List.h>
#include <String.h>
#include <Url.h>
#include <tinyxml2.h>
#include "Config.h"
class Entry {
public:
BString title;
BString description;
BString feedTitle;
BDateTime date;
BString postUrl;
BString content;
BString outputDir;
Entry(BString);
@ -32,6 +34,16 @@ public:
bool SetPostUrl(tinyxml2::XMLElement*);
bool SetDate(const char*);
bool SetDate(tinyxml2::XMLElement*);
BString title;
BString description;
BString feedTitle;
BDateTime date;
BString postUrl;
BString content;
BString outputDir;
};
#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 "App.h"
#include "Entry.h"
#include "Config.h"
#include "Util.h"
#include "Feed.h"
Feed::Feed(BString path)
{
@ -17,6 +25,7 @@ Feed::Feed ( BString path )
SetCachePath(path);
}
Feed::Feed()
{
title = BString("");
@ -25,25 +34,23 @@ Feed::Feed ( )
xmlUrl = BString("");
}
// ----------------------------------------------------------------------------
void
Feed::Parse()
{
BFile* feedFile = new BFile(GetCachePath().String(), B_READ_ONLY);
time_t tt_lastDate = 0;
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) {
attrLastDate.SetTime_t(tt_lastDate);
minDate = attrLastDate;
}
}
// -------------------------------------
// -------------------------------------
// Download a remote feed's XML to the cache path.
BString
@ -74,7 +81,6 @@ Feed::FetchRemoteFeed ( )
return GetCachePath();
}
// ----------------------------------------------------------------------------
// return whether or not the feed's given URI/path is remote.
bool
@ -83,6 +89,7 @@ Feed::IsRemote ( )
return isRemotePath(inputPath);
}
// return whether or not the feed seems to have been updated
bool
Feed::IsUpdated ()
@ -90,6 +97,7 @@ Feed::IsUpdated ( )
return updated;
}
// return whether or not feed is RSS
bool
Feed::IsRss ()
@ -103,6 +111,7 @@ Feed::IsRss ( )
return false;
}
// return whether or not feed is Atom
bool
Feed::IsAtom ()
@ -115,7 +124,6 @@ Feed::IsAtom ( )
return false;
}
// ----------------------------------------------------------------------------
// ensure the feed XML is available at the cache path.
// if necessary, download it.
@ -126,6 +134,7 @@ Feed::EnsureCached ( )
FetchRemoteFeed();
}
// Return the 'cachePath' (location of XML file locally)
BString
Feed::GetCachePath ()
@ -135,6 +144,7 @@ Feed::GetCachePath ( )
return cachePath;
}
// Select a 'cachePath' (location of XML file locally)
// For remote files, a cache file is created in ~/config/cache/Pogger/ by default
// For local files, the same local file is used.
@ -160,7 +170,6 @@ Feed::SetCachePath ( BString givenPath )
return filename;
}
// ----------------------------------------------------------------------------
// count the amount of siblings to an element of given type name
int
@ -174,7 +183,6 @@ Feed::xmlCountSiblings ( tinyxml2::XMLElement* xsibling, const char* sibling_nam
return count;
}
// ----------------------------------------------------------------------------
// add the given entry to the feed, if appropriate
bool
@ -190,44 +198,98 @@ Feed::AddEntry ( Entry* newEntry )
entries.AddItem(newEntry);
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;
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;
}
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;
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;
}
BString Feed::GetDesc ( ) { return description; }
BString
Feed::GetDesc()
{
return description;
}
// set a feed's «home URL»
bool Feed::SetHomeUrl ( const char* homepageStr ) {
if ( homepageStr != NULL ) homeUrl = BString( homepageStr );
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() );
bool
Feed::SetHomeUrl(tinyxml2::XMLElement* elem)
{
if (elem != NULL)
return SetHomeUrl(elem->GetText());
else return false;
}
BString Feed::GetHomeUrl ( ) { return homeUrl; }
BString
Feed::GetHomeUrl()
{
return homeUrl;
}
// set the update time for a feed
bool Feed::SetDate ( const char* dateCStr ) {
bool
Feed::SetDate(const char* dateCStr)
{
if (dateCStr == NULL)
return false;
BDateTime newDate = feedDateToBDate(dateCStr);
@ -236,9 +298,21 @@ bool Feed::SetDate ( const char* dateCStr ) {
date = newDate;
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;
}
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
#define FEED_H
#include <tinyxml2.h>
#include <DateTime.h>
#include <String.h>
#include <List.h>
#include <Url.h>
#include "Entry.h"
class BDateTime;
class BString;
class BList;
class BUrl;
class Feed {
public:
Feed(BString);
@ -57,7 +66,8 @@ protected:
BList entries;
bool fetched;
bool updated;
};
#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 <String.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 "Invocation.h"
#include "AtomFeed.h"
#include "Config.h"
#include "Entry.h"
#include "Feed.h"
#include "Mimetypes.h"
#include "RssFeed.h"
#include "Util.h"
int
usage()
@ -18,6 +27,7 @@ usage ( )
return 2;
}
int
invocation(int argc, char** argv)
{
@ -97,7 +107,6 @@ invocation ( int argc, char** argv )
}
}
// -------------------------------------
void
freeargInvocation(int argc, char** argv, int optind)
@ -114,7 +123,6 @@ freeargInvocation ( int argc, char** argv, int optind )
}
}
// ----------------------------------------------------------------------------
bool
processEntry(void* entry)
@ -124,6 +132,7 @@ processEntry ( void* entry )
return false;
}
bool
processFeed(void* feedArg)
{
@ -131,7 +140,8 @@ processFeed ( void* feedArg )
Feed* testFeed = new Feed(*(feedStr));
BList entries;
if ( testFeed->IsUpdated() == false && ((App*)be_app)->cfg->updateFeeds == true )
if (testFeed->IsUpdated() == false
&& ((App*)be_app)->cfg->updateFeeds == true)
return false;
if (testFeed->IsAtom()) {
@ -150,3 +160,5 @@ processFeed ( void* feedArg )
entries.DoForEach(&processEntry);
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
#define INVOCATION_H
#include <StorageKit.h>
int usage ( );
int invocation ( int, char** );
@ -9,6 +12,6 @@ void freeargInvocation ( int, char**, int );
bool processItem ( void* );
bool processFeed ( void* );
// ----------------------------------------------------------------------------
#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 <DateTime.h>
#include <Message.h>
#include <MimeType.h>
#include "Mimetypes.h"
// install the Feed Entry mimetype, if need be
bool
@ -12,9 +17,9 @@ feedMimeType ( )
{
BMessage info;
BMimeType mime("text/x-feed-entry");
if ( mime.IsInstalled() ) return true;
if (mime.IsInstalled())
return true;
std::cout << "NOT INSTALLED";
mime.GetAttrInfo(&info);
mime.SetShortDescription("Feed Entry");
@ -29,12 +34,12 @@ feedMimeType ( )
return mime.SetAttrInfo(&info);
}
// -------------------------------------
// add the given attribute to a BMessage for use as attr info
// borrowed from mailserver (thanks!)
static void
addAttribute
( BMessage& msg, const char* name, const char* publicName, int32 type, int32 width )
addAttribute(BMessage& msg, const char* name, const char* publicName,
int32 type, int32 width)
{
msg.AddString("attr:name", name);
msg.AddString("attr:public_name", publicName);
@ -45,3 +50,5 @@ addAttribute
msg.AddBool("attr:viewable", 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
#define MIME_H
#include <Message.h>
#include <String.h>
#include <SupportDefs.h>
#include <TypeConstants.h>
class BMessage;
bool feedMimeType();
static void addAttribute
( BMessage&, const char*, const char*, int32 type = B_STRING_TYPE, int32 width = 200);
static void addAttribute(BMessage&, const char*, const char*,
int32 type = B_STRING_TYPE, int32 width = 200);
#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 <sstream>
#include <UrlProtocolListener.h>
#include <Url.h>
#include <boost/uuid/detail/sha1.hpp>
#include "ProtocolListener.h"
ProtocolListener::ProtocolListener(bool traceLogging)
:
@ -11,11 +17,14 @@ ProtocolListener::ProtocolListener ( bool traceLogging )
fTraceLogging(traceLogging)
{}
ProtocolListener::~ProtocolListener()
{}
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)
fDownloadIO->Write(data, size);
@ -23,30 +32,35 @@ ProtocolListener::DataReceived ( BUrlRequest* caller, const char* data, off_t po
fSha1->process_bytes(data, size);
}
void
ProtocolListener::SetDownloadIO(BDataIO* downloadIO)
{
fDownloadIO = downloadIO;
}
BDataIO*
ProtocolListener::GetDownloadIO()
{
return fDownloadIO;
}
void
ProtocolListener::SetSha1(boost::uuids::detail::sha1* sha1)
{
fSha1 = sha1;
}
boost::uuids::detail::sha1*
ProtocolListener::GetSha1()
{
return fSha1;
}
BString
ProtocolListener::GetHash()
{
@ -61,3 +75,4 @@ ProtocolListener::GetHash ( )
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
#define PROTOCOL_LISTENER_H
#include <UrlProtocolListener.h>
#include <Url.h>
#include <boost/uuid/detail/sha1.hpp>
#include <UrlProtocolListener.h>
class ProtocolListener : public BUrlProtocolListener
{
public:
ProtocolListener(bool);
virtual ~ProtocolListener();
virtual void DataReceived(BUrlRequest*, const char*, off_t, ssize_t);
void SetDownloadIO(BDataIO*);
@ -26,4 +31,6 @@ private:
bool fTraceLogging;
};
#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 "Config.h"
#include "Entry.h"
#include "Util.h"
#include "RssFeed.h"
RssFeed::RssFeed()
{
@ -14,10 +20,10 @@ RssFeed::RssFeed ( )
outputDir = ((App*)be_app)->cfg->outDir;
}
RssFeed::RssFeed(Feed* feed) : RssFeed::RssFeed()
{ SetCachePath(feed->GetCachePath()); }
// ----------------------------------------------------------------------------
void
RssFeed::Parse()
@ -38,7 +44,6 @@ RssFeed::Parse ( )
feedFile->WriteAttr("LastDate", B_TIME_TYPE, 0, &tt_lastDate, sizeof(time_t));
}
// -------------------------------------
void
RssFeed::RootParse(tinyxml2::XMLElement* xchan)
@ -52,6 +57,7 @@ RssFeed::RootParse ( tinyxml2::XMLElement* xchan )
printf("Channel '%s' at '%s':\n", title.String(), homeUrl.String());
}
void
RssFeed::EntryParse(tinyxml2::XMLElement* xitem)
{
@ -71,6 +77,7 @@ RssFeed::EntryParse ( tinyxml2::XMLElement* xitem )
AddEntry(newEntry);
}
void
RssFeed::ParseEntries(tinyxml2::XMLElement* xchan)
{
@ -89,3 +96,5 @@ RssFeed::ParseEntries ( tinyxml2::XMLElement* xchan )
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
#define RSS_FEED_H
#include <tinyxml2.h>
#include <DateTime.h>
#include <String.h>
#include <List.h>
#include <Url.h>
#include "Feed.h"
class RssFeed: public Feed {
public:
RssFeed();
@ -19,4 +21,6 @@ public:
void ParseEntries(tinyxml2::XMLElement*);
};
#endif

View File

@ -1,37 +1,45 @@
#include <iostream>
#include <sstream>
#include <locale>
#include <iomanip>
#include <DateTime.h>
#include <UrlProtocolRoster.h>
#include <Url.h>
#include <UrlRequest.h>
#include <boost/uuid/detail/sha1.hpp>
#include "ProtocolListener.h"
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#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
feedDateToBDate(const char* dateCStr)
{
BDateTime date = dateRfc822ToBDate(dateCStr);
if ( date == NULL ) date = dateRfc3339ToBDate( dateCStr );
if (date == NULL)
date = dateRfc3339ToBDate(dateCStr);
return date;
}
BDateTime
dateRfc3339ToBDate(const char* dateCStr)
{
return stringDateToBDate(dateCStr, "%Y-%m-%dT%H:%M:%S");
}
BDateTime
dateRfc822ToBDate(const char* dateCStr)
{
return stringDateToBDate(dateCStr, "%a, %d %b %Y %H:%M:%S");
}
BDateTime
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)) {
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 NULL;
}
// ----------------------------------------------------------------------------
BString
dateTo3339String(BDateTime dt)
@ -59,7 +67,6 @@ dateTo3339String ( BDateTime dt )
return BString(buffer);
}
// ----------------------------------------------------------------------------
bool
withinDateRange(BDateTime minDate, BDateTime nowDate, BDateTime maxDate)
@ -73,7 +80,6 @@ withinDateRange ( BDateTime minDate, BDateTime nowDate, BDateTime maxDate )
return true;
}
// ----------------------------------------------------------------------------
// return whether or not the given path is remote
bool
@ -81,12 +87,12 @@ isRemotePath ( BString path ) {
BUrl givenUrl = BUrl(path);
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 true;
}
// ----------------------------------------------------------------------------
int32
webFetch(BUrl url, BDataIO* reply)
@ -115,3 +121,5 @@ webFetch ( BUrl url, BDataIO* reply, BString* hash )
return request->Status();
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
#define UTIL_H
#include <DateTime.h>
#include <Url.h>
#include "ProtocolListener.h"
class BUrl;
BDateTime feedDateToBDate(const char*);
BDateTime dateRfc3339ToBDate(const char*);
BDateTime dateRfc822ToBDate(const char*);
@ -19,4 +26,6 @@ bool isRemotePath ( BString );
int32 webFetch(BUrl, BDataIO*, BString*);
int32 webFetch(BUrl, BDataIO*);
#endif