From f921d9f6c3ef005db8f9e6a748d9e557b91d4b36 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Fri, 19 Jun 2020 17:54:41 -0500 Subject: [PATCH] Split Fetch into ProtocolListener and webfetch --- Makefile | 3 ++- src/Fetch.h | 46 --------------------------------- src/Item.cpp | 13 ++++++++++ src/Item.h | 24 +++++++++++++++++ src/ProtocolListener.cpp | 31 ++++++++++++++++++++++ src/ProtocolListener.h | 22 ++++++++++++++++ src/{Fetch.cpp => webfetch.cpp} | 10 +++---- src/webfetch.h | 9 +++++++ 8 files changed, 106 insertions(+), 52 deletions(-) delete mode 100644 src/Fetch.h create mode 100644 src/Item.cpp create mode 100644 src/Item.h create mode 100644 src/ProtocolListener.cpp create mode 100644 src/ProtocolListener.h rename src/{Fetch.cpp => webfetch.cpp} (73%) create mode 100644 src/webfetch.h diff --git a/Makefile b/Makefile index 5c180d1..4b10997 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,8 @@ APP_MIME_SIG = application/x-vnd.Rifen SRCS = \ src/Channel.cpp, \ src/Item.cpp, \ - src/Fetch.cpp, \ + src/ProtocolListener.cpp, \ + src/webfetch.cpp, \ src/parsing.cpp, \ src/Rifen.cpp diff --git a/src/Fetch.h b/src/Fetch.h deleted file mode 100644 index 32a3b31..0000000 --- a/src/Fetch.h +++ /dev/null @@ -1,46 +0,0 @@ -#include -#include - -class ProtocolListener : public BUrlProtocolListener -{ -public: - ProtocolListener(bool traceLogging) - : - fDownloadIO(NULL), - fTraceLogging(traceLogging) - { - } - - virtual ~ProtocolListener() - { - } - - virtual void DataReceived(BUrlRequest* caller, const char* data, - off_t position, ssize_t size) - { - if (fDownloadIO != NULL) { - fDownloadIO->Write(data, size); - } - } - - void - SetDownloadIO ( BDataIO* downloadIO ) - { - fDownloadIO = downloadIO; - } - - BDataIO* - GetDownloadIO ( ) - { - return fDownloadIO; - } - -private: - BDataIO* fDownloadIO; - bool fTraceLogging; -}; - -// ---------------------------------------------------------------------------- - -int32 fetch ( BUrl, BDataIO* ); -int32 fetch ( char*, BDataIO* ); diff --git a/src/Item.cpp b/src/Item.cpp new file mode 100644 index 0000000..8e38e66 --- /dev/null +++ b/src/Item.cpp @@ -0,0 +1,13 @@ +#include +#include +#include "Item.h" + +Item::Item ( BString localSubject ) +{ + subject = localSubject; + title = BString(""); + description = BString(""); + homePage = BString(""); + postUrl = BString(""); + content = BString(""); +} diff --git a/src/Item.h b/src/Item.h new file mode 100644 index 0000000..0e27f37 --- /dev/null +++ b/src/Item.h @@ -0,0 +1,24 @@ +#ifndef ITEM_H +#define ITEM_H + +#include +#include +#include +#include + +class Item { +public: + BString title; + BString description; + BDate pubDate; + BString homePage; + BString postUrl; + BString content; + + BString subject; + + void Print ( void ); + Item ( BString ); +}; + +#endif diff --git a/src/ProtocolListener.cpp b/src/ProtocolListener.cpp new file mode 100644 index 0000000..48e5d87 --- /dev/null +++ b/src/ProtocolListener.cpp @@ -0,0 +1,31 @@ +#include +#include +#include "ProtocolListener.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); +} + +void +ProtocolListener::SetDownloadIO ( BDataIO* downloadIO ) +{ + fDownloadIO = downloadIO; +} + +BDataIO* +ProtocolListener::GetDownloadIO ( ) +{ + return fDownloadIO; +} diff --git a/src/ProtocolListener.h b/src/ProtocolListener.h new file mode 100644 index 0000000..49941cd --- /dev/null +++ b/src/ProtocolListener.h @@ -0,0 +1,22 @@ +#ifndef PROTOCOL_LISTENER_H +#define PROTOCOL_LISTENER_H + +#include +#include + +class ProtocolListener : public BUrlProtocolListener +{ +public: + ProtocolListener(bool traceLogging); + + virtual ~ProtocolListener(); + virtual void DataReceived(BUrlRequest*, const char*, off_t, ssize_t); + void SetDownloadIO ( BDataIO* ); + BDataIO* GetDownloadIO ( ); + +private: + BDataIO* fDownloadIO; + bool fTraceLogging; +}; + +#endif diff --git a/src/Fetch.cpp b/src/webfetch.cpp similarity index 73% rename from src/Fetch.cpp rename to src/webfetch.cpp index b0e0584..2d97442 100644 --- a/src/Fetch.cpp +++ b/src/webfetch.cpp @@ -1,18 +1,18 @@ #include -#include "Fetch.h" +#include "ProtocolListener.h" +#include "webfetch.h" // ---------------------------------------------------------------------------- int32 -fetch ( char* strUrl, BDataIO* reply ) +webfetch ( char* strUrl, BDataIO* reply ) { - BUrl url( strUrl ); - return fetch( url, reply ); + return webfetch( BUrl(strUrl), reply ); } int32 -fetch ( BUrl url, BDataIO* reply ) +webfetch ( BUrl url, BDataIO* reply ) { ProtocolListener listener(true); BUrlContext context; diff --git a/src/webfetch.h b/src/webfetch.h new file mode 100644 index 0000000..c6d480d --- /dev/null +++ b/src/webfetch.h @@ -0,0 +1,9 @@ +#ifndef WEBFETCH_H +#define WEBFETCH_H +#include +#include "ProtocolListener.h" + +int32 webfetch ( BUrl, BDataIO* ); +int32 webfetch ( char*, BDataIO* ); + +#endif