diff --git a/Makefile b/Makefile index 2ebd54c..a54c225 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/FeedController.cpp b/src/FeedController.cpp index 977c3ec..ca69d6e 100644 --- a/src/FeedController.cpp +++ b/src/FeedController.cpp @@ -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(); diff --git a/src/ProtocolListener.cpp b/src/ProtocolListener.cpp deleted file mode 100644 index 380b238..0000000 --- a/src/ProtocolListener.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2020, Jaidyn Levesque - * All rights reserved. Distributed under the terms of the MIT license. - */ - -#include "ProtocolListener.h" - -#include -#include - -#include - - -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 - * All rights reserved. Distributed under the terms of the MIT license. - */ -#ifndef PROTOCOL_LISTENER_H -#define PROTOCOL_LISTENER_H - -#include - -#include - -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 - diff --git a/src/Util.cpp b/src/Util.cpp index 7786166..15f02b1 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -21,9 +21,7 @@ #include #include -#include - -#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; diff --git a/src/Util.h b/src/Util.h index 173699b..93693f3 100644 --- a/src/Util.h +++ b/src/Util.h @@ -9,9 +9,8 @@ #include #include -#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).