Split Fetch into ProtocolListener and webfetch

This commit is contained in:
Jaidyn Ann 2020-06-19 17:54:41 -05:00
parent 95d20c751c
commit f921d9f6c3
8 changed files with 106 additions and 52 deletions

View File

@ -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

View File

@ -1,46 +0,0 @@
#include <UrlProtocolListener.h>
#include <Url.h>
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* );

13
src/Item.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <cstdio>
#include <raptor2/raptor2.h>
#include "Item.h"
Item::Item ( BString localSubject )
{
subject = localSubject;
title = BString("");
description = BString("");
homePage = BString("");
postUrl = BString("");
content = BString("");
}

24
src/Item.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef ITEM_H
#define ITEM_H
#include <DateTime.h>
#include <String.h>
#include <List.h>
#include <Url.h>
class Item {
public:
BString title;
BString description;
BDate pubDate;
BString homePage;
BString postUrl;
BString content;
BString subject;
void Print ( void );
Item ( BString );
};
#endif

31
src/ProtocolListener.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <UrlProtocolListener.h>
#include <Url.h>
#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;
}

22
src/ProtocolListener.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef PROTOCOL_LISTENER_H
#define PROTOCOL_LISTENER_H
#include <UrlProtocolListener.h>
#include <Url.h>
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

View File

@ -1,18 +1,18 @@
#include <HttpRequest.h>
#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;

9
src/webfetch.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef WEBFETCH_H
#define WEBFETCH_H
#include <Url.h>
#include "ProtocolListener.h"
int32 webfetch ( BUrl, BDataIO* );
int32 webfetch ( char*, BDataIO* );
#endif