From 547a9c6fde7ce675129f9050267ec7b2a88e0c85 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Sat, 27 Oct 2018 11:46:12 +0200 Subject: [PATCH] ... --- HTTPSStream.hh | 38 ++++++++++++++++++++++++++++++++++++++ Makefile | 10 +++++++++- UpdateStream.cc | 23 +++++++++++++++++++++++ UpdateStream.hh | 42 ++++++++++++++++++++++++++++++++++++++++++ downloadclient.cc | 34 +++++++++++++++++++++------------- downloadclient.hh | 16 ++++++++++++++++ 6 files changed, 149 insertions(+), 14 deletions(-) create mode 100644 HTTPSStream.hh create mode 100644 UpdateStream.cc create mode 100644 UpdateStream.hh create mode 100644 downloadclient.hh diff --git a/HTTPSStream.hh b/HTTPSStream.hh new file mode 100644 index 0000000..815b5db --- /dev/null +++ b/HTTPSStream.hh @@ -0,0 +1,38 @@ +// this file is under GNU General Public License 3.0 +// see LICENSE.txt + +#pragma once + +#include +#include +#include + +namespace pEp { + using namespace std; + namespace io = boost::iostreams; + + struct url_split { + string protocol; + string login; + string password; + string host; + string port; + string path; + string hash; + }; + + url_split split_url(string url); + + class HTTPSDevice : public io::device< io::bidirectional > { + boost::asio::io_context _ioc; + + public: + void open(string url); + + streamsize read(char* s, streamsize n); + streamsize write(const char* s, streamsize n); + }; + + typedef io::stream< HTTPSDevice > HTTPSStream; +} + diff --git a/Makefile b/Makefile index e201942..6de5c6d 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,12 @@ include Makefile.conf -include local.conf CXXFLAGS += -std=c++14 -O0 -g +LDFLAGS += -lboost_regex-mt -lboost_iostreams-mt -lboost_system-mt SOURCE=$(wildcard *.cc) HEADERS=$(wildcard *.hh *.hxx) OBJECTS=$(subst .cc,.o,$(SOURCE)) -WITHOUT_TESTS=$(patsubst test%.o,,$(OBJECTS)) +WITHOUT_TESTS=$(patsubst test_%.o,,$(OBJECTS)) all: $(TARGET) @@ -23,6 +24,7 @@ $(TARGET): $(WITHOUT_TESTS) clean: rm -f $(TARGET) $(OBJECTS) *.a + rm -f test_split_url install: $(TARGET) -mkdir -p $(PEP)/include/pEp @@ -32,3 +34,9 @@ install: $(TARGET) uninstall: cd $(PEP)/include && rm -f $(HEADERS) cd $(PEP)/lib && rm -f $(TARGET) + +test_split_url: test_split_url.o HTTPSStream.o + $(CXX) $(LDFLAGS) $< HTTPSStream.o -o $@ + +test: test_split_url + ./test_split_url diff --git a/UpdateStream.cc b/UpdateStream.cc new file mode 100644 index 0000000..3982857 --- /dev/null +++ b/UpdateStream.cc @@ -0,0 +1,23 @@ +// this file is under GNU General Public License 3.0 +// see LICENSE.txt + +#include "UpdateStream.hh" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace pEp { + namespace UpdateClient { + UpdateDevice::UpdateDevice(const product& p) + { + + } + } +} + diff --git a/UpdateStream.hh b/UpdateStream.hh new file mode 100644 index 0000000..4598039 --- /dev/null +++ b/UpdateStream.hh @@ -0,0 +1,42 @@ +// this file is under GNU General Public License 3.0 +// see LICENSE.txt + +#pragma once + +#include +#include +#include + +#include "HTTPSStream.hh" + +namespace pEp { + namespace UpdateClient { + using namespace std; + namespace io = boost::iostreams; + + struct NoUpdateAvailable : runtime_error { }; + + struct product { + string name; + string url; + string serial; + }; + + class UpdateDevice + { + HTTPSStream _https; + + public: + UpdateDevice(const product& p); + + typedef char char_type; + typedef io::bidirectional_device_tag category; + + streamsize read(char* s, streamsize n); + streamsize write(const char* s, streamsize n); + }; + + typedef io::stream< UpdateDevice > UpdateStream; + } +} + diff --git a/downloadclient.cc b/downloadclient.cc index 6dd4473..e0182fc 100644 --- a/downloadclient.cc +++ b/downloadclient.cc @@ -1,17 +1,25 @@ +// this file is under GNU General Public License 3.0 +// see LICENSE.txt + +#include "downloadclient.hh" +#include "UpdateStream.hh" + #include -#include -#include -#include #include -#include - -#include -#include -#include -#include -#include -#include -#include -#include +namespace pEp { + namespace UpdateClient { + /* + istream update(const product& p) + { + try { + return UpdateStream(p); + } + catch (NoUpdateAvailable&) { + return stringstream(string("")); + } + } + */ + } +} diff --git a/downloadclient.hh b/downloadclient.hh new file mode 100644 index 0000000..c72f427 --- /dev/null +++ b/downloadclient.hh @@ -0,0 +1,16 @@ +// this file is under GNU General Public License 3.0 +// see LICENSE.txt + +#pragma once + +#include +#include "UpdateStream.hh" + +namespace pEp { + namespace UpdateClient { + using namespace std; + + istream update(const product& p); + } +} +