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/Mimetypes.cpp, \
src/Notifier.cpp, \ src/Notifier.cpp, \
src/Preferences.cpp, \ src/Preferences.cpp, \
src/ProtocolListener.cpp, \
src/RssFeed.cpp, \ src/RssFeed.cpp, \
src/UpdatesView.cpp, \ src/UpdatesView.cpp, \
src/Util.cpp src/Util.cpp

View File

@ -247,7 +247,7 @@ FeedController::_ParseLoop(void* data)
BUrl feedUrl = feedBuffer->GetXmlUrl(); BUrl feedUrl = feedBuffer->GetXmlUrl();
BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->EntryDir()); BDirectory outDir = BDirectory(((App*)be_app)->fPreferences->EntryDir());
if (feedBuffer->IsAtom()) { if (feedBuffer->IsAtom() && feedBuffer->IsUpdated()) {
AtomFeed feed(feedBuffer); AtomFeed feed(feedBuffer);
feed.Parse(); feed.Parse();
entries = feed.GetNewEntries(); entries = feed.GetNewEntries();
@ -258,7 +258,7 @@ FeedController::_ParseLoop(void* data)
entries.ItemAt(i)->Filetize(outDir); entries.ItemAt(i)->Filetize(outDir);
entries.MakeEmpty(); entries.MakeEmpty();
} }
else if (feedBuffer->IsRss()) { else if (feedBuffer->IsRss() && feedBuffer->IsUpdated()) {
RssFeed feed(feedBuffer); RssFeed feed(feedBuffer);
feed.Parse(); feed.Parse();
entries = feed.GetNewEntries(); 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 <UrlProtocolRoster.h>
#include <UrlRequest.h> #include <UrlRequest.h>
#include <boost/uuid/detail/sha1.hpp> using namespace BPrivate::Network;
#include "ProtocolListener.h"
BDateTime BDateTime
@ -134,21 +132,30 @@ tempFileName(const char* dir, const char* name, const char* suffix)
} }
int32 BString
fetch(BUrl url, BDataIO* reply, BString* hash, int timeout) hashFile(BFile* file)
{ {
ProtocolListener listener(true); const int size = 1000;
boost::uuids::detail::sha1 sha1; char data[size] = {'\0'};
BString hashString;
ssize_t read = 0;
int index = 0;
#ifdef LIBNETAPI_DEPRECATED do {
BUrlRequest* request = BUrlProtocolRoster::MakeRequest(url, &listener); read = file->ReadAt((off_t)index * size, (void*)data, size);
listener.SetDownloadIO(reply); hashString << abs((int)data[0] % 10);
#else index++;
BUrlRequest* request = BUrlProtocolRoster::MakeRequest(url, reply, &listener); }
listener.SetDownloadIO(NULL); while (read == size && index < 30);
#endif
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); time_t startTime = time(0);
thread_id thread = request->Run(); thread_id thread = request->Run();
@ -160,7 +167,7 @@ fetch(BUrl url, BDataIO* reply, BString* hash, int timeout)
kill_thread(thread); kill_thread(thread);
*(hash) = listener.GetHash(); *(hash) = hashFile(reply);
int32 status = request->Status(); int32 status = request->Status();
delete request; delete request;

View File

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