From 21ad59927f81634d9fd8c5b04f17a08af3c9882a Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 2 Aug 2020 03:29:56 -0500 Subject: [PATCH] Custom entry mimetype; remove --mimetype --- Makefile | 3 ++- src/Config.cpp | 3 --- src/Config.h | 1 - src/Entry.cpp | 23 ++++++++++------------- src/Mimetypes.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/Mimetypes.h | 14 ++++++++++++++ src/Pogger.cpp | 6 ++---- src/Pogger.h | 5 ++--- 8 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 src/Mimetypes.cpp create mode 100644 src/Mimetypes.h diff --git a/Makefile b/Makefile index 364ec4c..586eb2e 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ SRCS = \ src/AtomFeed.cpp, \ src/RssFeed.cpp, \ src/ProtocolListener.cpp, \ + src/Mimetypes.cpp, \ src/Config.cpp, \ src/Util.cpp, \ src/Pogger.cpp @@ -41,7 +42,7 @@ SRCS = \ # Specify the resource definition files to use. Full or relative paths can be # used. RDEFS = # \ -# src/calendar.rdef \ + # src/Pogger.rdef \ # Specify the resource files to use. Full or relative paths can be used. diff --git a/src/Config.cpp b/src/Config.cpp index 4b16cda..e16da1d 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -24,8 +24,6 @@ Config::Load () BMessage storage; storage.Unflatten( file ); - if ( mimetype == NULL) - mimetype = BString( storage.GetString("mimetype", "text/xml") ); if ( outDir == NULL) outDir = BString( storage.GetString("outDir", "/boot/home/feeds/") ); if ( cacheDir == NULL) @@ -55,7 +53,6 @@ Config::Save () BFile* file = new BFile( filename.String(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE ); status_t result = file->InitCheck(); - storage.AddString( "mimetype", mimetype.String() ); storage.AddString( "outDir", outDir.String() ); storage.AddString( "cacheDir", cacheDir.String() ); diff --git a/src/Config.h b/src/Config.h index 8fac7b8..0a66ba2 100644 --- a/src/Config.h +++ b/src/Config.h @@ -9,7 +9,6 @@ class Config { public: bool verbose; bool daemon; - BString mimetype; BString outDir; BList targetFeeds; // strings of files or urls diff --git a/src/Entry.cpp b/src/Entry.cpp index 8db85f2..6c5efa3 100644 --- a/src/Entry.cpp +++ b/src/Entry.cpp @@ -20,27 +20,24 @@ Entry::Filetize ( Config* cfg, bool onlyIfNew = false ) { BDirectory* dir = new BDirectory( outputDir ); BFile* file = new BFile( title.String(), B_READ_WRITE ); + time_t tt_date = date.Time_t(); dir->CreateFile( title.String(), file ); - BString betype = cfg->mimetype; - if ( date != NULL ) { - int32 unixDate = (int32)date.Time_t(); - file->WriteAttr( "unixDate", B_INT32_TYPE, 0, - &unixDate, sizeof(int32) ); - file->WriteAttr( "date", B_STRING_TYPE, 0, - dateTo3339String(date).String(), - dateTo3339String(date).CountChars() ); - } + BString betype = BString("text/x-feed-entry"); + file->WriteAttr( "BEOS:TYPE", B_MIME_STRING_TYPE, 0, + betype.String(), betype.CountChars() + 1 ); - file->WriteAttr( "META:title", B_STRING_TYPE, 0, + file->WriteAttr( "FEED:name", B_STRING_TYPE, 0, title.String(), title.CountChars() ); - file->WriteAttr( "description", B_STRING_TYPE, 0, + file->WriteAttr( "FEED:description", B_STRING_TYPE, 0, description.String(), description.CountChars() ); file->WriteAttr( "META:url", B_STRING_TYPE, 0, postUrl.String(), postUrl.CountChars() ); - file->WriteAttr( "BEOS:TYPE", B_STRING_TYPE, 0, - betype.String(), betype.CountChars() ); + if ( date != NULL ) { + file->WriteAttr( "FEED:when", B_TIME_TYPE, 0, + &tt_date, sizeof(time_t) ); + } file->Write(content.String(), content.Length()); return false; diff --git a/src/Mimetypes.cpp b/src/Mimetypes.cpp new file mode 100644 index 0000000..330be33 --- /dev/null +++ b/src/Mimetypes.cpp @@ -0,0 +1,47 @@ +// borrowed significantly from mailserver. thanks! <3 +#include +#include +#include +#include "Mimetypes.h" + +bool +feedMimeType ( ) +{ + BMessage info; + BMimeType mime( "text/x-feed-entry" ); + + if ( mime.InitCheck() != B_OK ) { + return false; + } + + if ( !mime.IsInstalled() ) { + mime.Delete(); + mime.Install(); + + addAttribute( info, "FEED:name", "Name" ); + addAttribute( info, "FEED:description", "Description" ); + addAttribute( info, "META:url", "URL" ); + addAttribute( info, "FEED:when", "When", B_TIME_TYPE, true, false, 150 ); + + mime.SetAttrInfo(&info); + + mime.SetShortDescription("Feed Entry"); + mime.SetLongDescription("RSS/Atom Feed Entry"); + } + return true; +} + +// ------------------------------------- + +static void +addAttribute +( BMessage& msg, const char* name, const char* publicName, int32 type, bool viewable, bool editable, + int32 width) +{ + msg.AddString( "attr:name", name ); + msg.AddString( "attr:public_name", publicName ); + msg.AddInt32( "attr:type", type ); + msg.AddBool( "attr:viewable", viewable ); + msg.AddBool( "attr:editable", editable ); + msg.AddInt32( "attr:width", width ); +} diff --git a/src/Mimetypes.h b/src/Mimetypes.h new file mode 100644 index 0000000..2501e3c --- /dev/null +++ b/src/Mimetypes.h @@ -0,0 +1,14 @@ +#ifndef MIME_H +#define MIME_H + +#include +#include + +bool feedMimeType ( ); + +static void addAttribute +( BMessage&, const char*, const char*, int32 type = B_STRING_TYPE, bool viewable = true, + bool editable = false, int32 width = 200); + + +#endif diff --git a/src/Pogger.cpp b/src/Pogger.cpp index 3055f6f..10c82cf 100644 --- a/src/Pogger.cpp +++ b/src/Pogger.cpp @@ -5,6 +5,7 @@ #include "RssFeed.h" #include "Feed.h" #include "Entry.h" +#include "Mimetypes.h" #include "Config.h" #include "Util.h" #include "Pogger.h" @@ -14,6 +15,7 @@ main ( int argc, char** argv ) { main_cfg = new Config; usageMsg.ReplaceAll("%app%", "Pogger"); + feedMimeType(); invocation( argc, argv, &main_cfg ); main_cfg->Load(); @@ -49,7 +51,6 @@ invocation ( int argc, char** argv, Config** cfgPtr ) { "before", required_argument, 0, 't' }, { "after", required_argument, 0, 'T' }, { "output", required_argument, 0, 'O' }, - { "mimetype", required_argument, 0, 'm' }, { "foreground", no_argument, 0, 'D' }, { 0, 0, 0, 0 } }; @@ -72,9 +73,6 @@ invocation ( int argc, char** argv, Config** cfgPtr ) break; case 's': cfg->will_save = true; - case 'm': - cfg->mimetype = BString( optarg ); - break; case 't': minDate = dateRfc3339ToBDate( optarg ); if ( minDate != NULL ) diff --git a/src/Pogger.h b/src/Pogger.h index c279574..d51af15 100644 --- a/src/Pogger.h +++ b/src/Pogger.h @@ -16,15 +16,14 @@ const char* configPath = "/boot/home/config/settings/Pogger/"; BString usageMsg = - "Usage: %app% [-hvDus] [-m mimetype] [-tT datetime] [-cCO path] \n" - " %app% [-hvs] [-mtTcCO] ( | | )\n" + "Usage: %app% [-hvDus] [-tT datetime] [-cCO path] \n" + " %app% [-hvs] [-tTcCO] ( | | )\n" "\n" "%app%, a RSS and Atom feed parser/daemon.\n" "\n" "Options:\n" " -h, --help - Print this usage info.\n" " -v, --verbose - Print verbose (debug) info.\n" - " -m, --mimetype - Mimetype of new item files. (Default: text/xml)\n" " -O, --output - Output dir for item files. (Default: ~/feeds/)\n" " -t, --before - Only return items published before this datetime.\n" " -T, --after - Only return items published after this datetime.\n"