Custom entry mimetype; remove --mimetype
This commit is contained in:
parent
0438c097bf
commit
21ad59927f
3
Makefile
3
Makefile
|
@ -34,6 +34,7 @@ SRCS = \
|
||||||
src/AtomFeed.cpp, \
|
src/AtomFeed.cpp, \
|
||||||
src/RssFeed.cpp, \
|
src/RssFeed.cpp, \
|
||||||
src/ProtocolListener.cpp, \
|
src/ProtocolListener.cpp, \
|
||||||
|
src/Mimetypes.cpp, \
|
||||||
src/Config.cpp, \
|
src/Config.cpp, \
|
||||||
src/Util.cpp, \
|
src/Util.cpp, \
|
||||||
src/Pogger.cpp
|
src/Pogger.cpp
|
||||||
|
@ -41,7 +42,7 @@ SRCS = \
|
||||||
# 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.
|
||||||
RDEFS = # \
|
RDEFS = # \
|
||||||
# src/calendar.rdef \
|
# src/Pogger.rdef \
|
||||||
|
|
||||||
|
|
||||||
# Specify the resource files to use. Full or relative paths can be used.
|
# Specify the resource files to use. Full or relative paths can be used.
|
||||||
|
|
|
@ -24,8 +24,6 @@ Config::Load ()
|
||||||
BMessage storage;
|
BMessage storage;
|
||||||
storage.Unflatten( file );
|
storage.Unflatten( file );
|
||||||
|
|
||||||
if ( mimetype == NULL)
|
|
||||||
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)
|
||||||
|
@ -55,7 +53,6 @@ Config::Save ()
|
||||||
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( "outDir", outDir.String() );
|
storage.AddString( "outDir", outDir.String() );
|
||||||
storage.AddString( "cacheDir", cacheDir.String() );
|
storage.AddString( "cacheDir", cacheDir.String() );
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ class Config {
|
||||||
public:
|
public:
|
||||||
bool verbose;
|
bool verbose;
|
||||||
bool daemon;
|
bool daemon;
|
||||||
BString mimetype;
|
|
||||||
BString outDir;
|
BString outDir;
|
||||||
BList targetFeeds; // strings of files or urls
|
BList targetFeeds; // strings of files or urls
|
||||||
|
|
||||||
|
|
|
@ -20,27 +20,24 @@ Entry::Filetize ( Config* cfg, 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 );
|
||||||
|
time_t tt_date = date.Time_t();
|
||||||
|
|
||||||
dir->CreateFile( title.String(), file );
|
dir->CreateFile( title.String(), file );
|
||||||
|
|
||||||
BString betype = cfg->mimetype;
|
BString betype = BString("text/x-feed-entry");
|
||||||
if ( date != NULL ) {
|
file->WriteAttr( "BEOS:TYPE", B_MIME_STRING_TYPE, 0,
|
||||||
int32 unixDate = (int32)date.Time_t();
|
betype.String(), betype.CountChars() + 1 );
|
||||||
file->WriteAttr( "unixDate", B_INT32_TYPE, 0,
|
|
||||||
&unixDate, sizeof(int32) );
|
|
||||||
file->WriteAttr( "date", B_STRING_TYPE, 0,
|
|
||||||
dateTo3339String(date).String(),
|
|
||||||
dateTo3339String(date).CountChars() );
|
|
||||||
}
|
|
||||||
|
|
||||||
file->WriteAttr( "META:title", B_STRING_TYPE, 0,
|
file->WriteAttr( "FEED:name", B_STRING_TYPE, 0,
|
||||||
title.String(), title.CountChars() );
|
title.String(), title.CountChars() );
|
||||||
file->WriteAttr( "description", B_STRING_TYPE, 0,
|
file->WriteAttr( "FEED:description", B_STRING_TYPE, 0,
|
||||||
description.String(), description.CountChars() );
|
description.String(), description.CountChars() );
|
||||||
file->WriteAttr( "META:url", B_STRING_TYPE, 0,
|
file->WriteAttr( "META:url", B_STRING_TYPE, 0,
|
||||||
postUrl.String(), postUrl.CountChars() );
|
postUrl.String(), postUrl.CountChars() );
|
||||||
file->WriteAttr( "BEOS:TYPE", B_STRING_TYPE, 0,
|
if ( date != NULL ) {
|
||||||
betype.String(), betype.CountChars() );
|
file->WriteAttr( "FEED:when", B_TIME_TYPE, 0,
|
||||||
|
&tt_date, sizeof(time_t) );
|
||||||
|
}
|
||||||
|
|
||||||
file->Write(content.String(), content.Length());
|
file->Write(content.String(), content.Length());
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
// borrowed significantly from mailserver. thanks! <3
|
||||||
|
#include <DateTime.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <MimeType.h>
|
||||||
|
#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 );
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef MIME_H
|
||||||
|
#define MIME_H
|
||||||
|
|
||||||
|
#include <Message.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
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
|
|
@ -5,6 +5,7 @@
|
||||||
#include "RssFeed.h"
|
#include "RssFeed.h"
|
||||||
#include "Feed.h"
|
#include "Feed.h"
|
||||||
#include "Entry.h"
|
#include "Entry.h"
|
||||||
|
#include "Mimetypes.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "Pogger.h"
|
#include "Pogger.h"
|
||||||
|
@ -14,6 +15,7 @@ main ( int argc, char** argv )
|
||||||
{
|
{
|
||||||
main_cfg = new Config;
|
main_cfg = new Config;
|
||||||
usageMsg.ReplaceAll("%app%", "Pogger");
|
usageMsg.ReplaceAll("%app%", "Pogger");
|
||||||
|
feedMimeType();
|
||||||
|
|
||||||
invocation( argc, argv, &main_cfg );
|
invocation( argc, argv, &main_cfg );
|
||||||
main_cfg->Load();
|
main_cfg->Load();
|
||||||
|
@ -49,7 +51,6 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
{ "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' },
|
||||||
{ "mimetype", required_argument, 0, 'm' },
|
|
||||||
{ "foreground", no_argument, 0, 'D' },
|
{ "foreground", no_argument, 0, 'D' },
|
||||||
{ 0, 0, 0, 0 }
|
{ 0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
@ -72,9 +73,6 @@ invocation ( int argc, char** argv, Config** cfgPtr )
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
cfg->will_save = true;
|
cfg->will_save = true;
|
||||||
case 'm':
|
|
||||||
cfg->mimetype = BString( optarg );
|
|
||||||
break;
|
|
||||||
case 't':
|
case 't':
|
||||||
minDate = dateRfc3339ToBDate( optarg );
|
minDate = dateRfc3339ToBDate( optarg );
|
||||||
if ( minDate != NULL )
|
if ( minDate != NULL )
|
||||||
|
|
|
@ -16,15 +16,14 @@ const char* configPath = "/boot/home/config/settings/Pogger/";
|
||||||
|
|
||||||
|
|
||||||
BString usageMsg =
|
BString usageMsg =
|
||||||
"Usage: %app% [-hvDus] [-m mimetype] [-tT datetime] [-cCO path] \n"
|
"Usage: %app% [-hvDus] [-tT datetime] [-cCO path] \n"
|
||||||
" %app% [-hvs] [-mtTcCO] ( <text/xml file> | <META:url file> | <url> )\n"
|
" %app% [-hvs] [-tTcCO] ( <text/xml file> | <META:url file> | <url> )\n"
|
||||||
"\n"
|
"\n"
|
||||||
"%app%, a RSS and Atom feed parser/daemon.\n"
|
"%app%, a RSS and Atom feed parser/daemon.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
" -h, --help - Print this usage info.\n"
|
" -h, --help - Print this usage info.\n"
|
||||||
" -v, --verbose - Print verbose (debug) 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"
|
" -O, --output - Output dir for item files. (Default: ~/feeds/)\n"
|
||||||
" -t, --before - Only return items published before this datetime.\n"
|
" -t, --before - Only return items published before this datetime.\n"
|
||||||
" -T, --after - Only return items published after this datetime.\n"
|
" -T, --after - Only return items published after this datetime.\n"
|
||||||
|
|
Ŝarĝante…
Reference in New Issue