Re-enable hashing of feeds

This commit is contained in:
Jaidyn Ann 2021-03-20 16:46:42 -05:00
parent ef3eec3689
commit 4027ed0c4f
6 changed files with 28 additions and 143 deletions

View File

@ -42,7 +42,6 @@ SRCS = \
src/Mimetypes.cpp, \
src/Notifier.cpp, \
src/Preferences.cpp, \
src/ProtocolListener.cpp, \
src/RssFeed.cpp, \
src/UpdatesView.cpp, \
src/Util.cpp

View File

@ -247,7 +247,7 @@ FeedController::_ParseLoop(void* data)
BUrl feedUrl = feedBuffer->GetXmlUrl();
BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->EntryDir());
if (feedBuffer->IsAtom()) {
if (feedBuffer->IsAtom() && feedBuffer->IsUpdated()) {
AtomFeed feed(feedBuffer);
feed.Parse();
entries = feed.GetNewEntries();
@ -258,7 +258,7 @@ FeedController::_ParseLoop(void* data)
entries.ItemAt(i)->Filetize(outDir);
entries.MakeEmpty();
}
else if (feedBuffer->IsRss()) {
else if (feedBuffer->IsRss() && feedBuffer->IsUpdated()) {
RssFeed feed(feedBuffer);
feed.Parse();
entries = feed.GetNewEntries();

View File

@ -1,78 +0,0 @@
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
#include "ProtocolListener.h"
#include <iostream>
#include <sstream>
#include <Url.h>
ProtocolListener::ProtocolListener(bool traceLogging)
:
fDownloadIO(NULL),
fTraceLogging(traceLogging)
{}
ProtocolListener::~ProtocolListener()
{}
void
ProtocolListener::DataReceived(BUrlRequest* caller, const char* data,
off_t position, ssize_t size)
{
if (fDownloadIO != NULL)
fDownloadIO->Write(data, size);
if (fSha1 != NULL)
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()
{
unsigned int hashInt[5];
fSha1->get_digest(hashInt);
std::ostringstream hashStr;
for(std::size_t i=0; i<sizeof(hashInt)/sizeof(hashInt[0]); ++i) {
hashStr << std::hex <<hashInt[i];
}
return BString(hashStr.str().c_str());
}

View File

@ -1,43 +0,0 @@
/*
* 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 <boost/uuid/detail/sha1.hpp>
#include <UrlProtocolListener.h>
class BDataIO;
#ifndef LIBNETAPI_DEPRECATED
using namespace BPrivate::Network;
#endif
class ProtocolListener : public BUrlProtocolListener
{
public:
ProtocolListener(bool);
virtual ~ProtocolListener();
virtual void DataReceived(BUrlRequest*, const char*, off_t, ssize_t);
void SetDownloadIO(BDataIO*);
BDataIO* GetDownloadIO();
void SetSha1(boost::uuids::detail::sha1*);
boost::uuids::detail::sha1* GetSha1();
BString GetHash();
private:
BDataIO* fDownloadIO;
boost::uuids::detail::sha1* fSha1;
bool fTraceLogging;
};
#endif

View File

@ -21,9 +21,7 @@
#include <UrlProtocolRoster.h>
#include <UrlRequest.h>
#include <boost/uuid/detail/sha1.hpp>
#include "ProtocolListener.h"
using namespace BPrivate::Network;
BDateTime
@ -134,21 +132,30 @@ tempFileName(const char* dir, const char* name, const char* suffix)
}
int32
fetch(BUrl url, BDataIO* reply, BString* hash, int timeout)
BString
hashFile(BFile* file)
{
ProtocolListener listener(true);
boost::uuids::detail::sha1 sha1;
const int size = 1000;
char data[size] = {'\0'};
BString hashString;
ssize_t read = 0;
int index = 0;
#ifdef LIBNETAPI_DEPRECATED
BUrlRequest* request = BUrlProtocolRoster::MakeRequest(url, &listener);
listener.SetDownloadIO(reply);
#else
BUrlRequest* request = BUrlProtocolRoster::MakeRequest(url, reply, &listener);
listener.SetDownloadIO(NULL);
#endif
do {
read = file->ReadAt((off_t)index * size, (void*)data, size);
hashString << abs((int)data[0] % 10);
index++;
}
while (read == size && index < 30);
listener.SetSha1(&sha1);
return hashString;
}
int32
fetch(BUrl url, BFile* reply, BString* hash, int timeout)
{
BUrlRequest* request = BUrlProtocolRoster::MakeRequest(url, reply);
time_t startTime = time(0);
thread_id thread = request->Run();
@ -160,7 +167,7 @@ fetch(BUrl url, BDataIO* reply, BString* hash, int timeout)
kill_thread(thread);
*(hash) = listener.GetHash();
*(hash) = hashFile(reply);
int32 status = request->Status();
delete request;

View File

@ -9,9 +9,8 @@
#include <DateTime.h>
#include <Entry.h>
#include "ProtocolListener.h"
class BBitmap;
class BFile;
class BUrl;
@ -29,7 +28,8 @@ bool isRemotePath(BString);
BString urlToFilename(BUrl url);
const char* tempFileName(const char* dir, const char* name, const char* suffix);
int32 fetch(BUrl url, BDataIO* reply, BString* hash, int timeout);
BString hashFile(BFile* file);
int32 fetch(BUrl url, BFile* reply, BString* hash, int timeout);
// The strings passed to this function are adapted from those in
// Calendar (utils/Preferences.cpp).