diff --git a/UpdateStream.hh b/UpdateStream.hh index 051131a..f79ed8c 100644 --- a/UpdateStream.hh +++ b/UpdateStream.hh @@ -19,8 +19,6 @@ namespace pEp { using namespace std; namespace io = boost::iostreams; - struct NoUpdateAvailable : runtime_error { }; - struct product { string name; string url; diff --git a/downloadclient.cc b/downloadclient.cc index e0182fc..97a3c31 100644 --- a/downloadclient.cc +++ b/downloadclient.cc @@ -2,24 +2,32 @@ // see LICENSE.txt #include "downloadclient.hh" -#include "UpdateStream.hh" #include #include namespace pEp { namespace UpdateClient { - /* - istream update(const product& p) + string update(product p, PublicKey update_key) { + UpdateStream us { UpdateDevice(p) }; + try { - return UpdateStream(p); - } - catch (NoUpdateAvailable&) { - return stringstream(string("")); + us->open(update_key); } + catch (exception&) { } + + if (us->filename() == "") + throw DownloadError(); + + return us->filename(); + } + + string update(product p, string keyfile) + { + PublicKey update_key = load_key(keyfile); + return update(p, update_key); } - */ } } diff --git a/downloadclient.hh b/downloadclient.hh index c72f427..2440b1c 100644 --- a/downloadclient.hh +++ b/downloadclient.hh @@ -10,7 +10,12 @@ namespace pEp { namespace UpdateClient { using namespace std; - istream update(const product& p); + struct DownloadError : runtime_error { + DownloadError() : runtime_error("download not possible") { } + }; + + string update(product p, PublicKey update_key); + string update(product p, string keyfile); } } diff --git a/test_updater.cc b/test_updater.cc index c5702fd..6f5f00a 100644 --- a/test_updater.cc +++ b/test_updater.cc @@ -3,14 +3,14 @@ #include #include -#include -#include "UpdateStream.hh" +#include "downloadclient.cc" using namespace std; using namespace pEp::UpdateClient; int main() { + /* product p { "pEp for Something", "https://fdik.org/cgidownload?hash=23232323234242" }; UpdateStream us { UpdateDevice(p) }; @@ -30,6 +30,20 @@ int main() str << us.rdbuf(); cout << str.str() << "\n"; } + */ + + cout << "downloading...\n"; + + product p { "pEp for Something", "https://fdik.org/cgidownload?hash=23232323234242" }; + + try { + string filename = update(p, "public.der"); + cout << "downloaded " << filename << "\n"; + } + catch (DownloadError&) + { + cout << "cannot download\n"; + } return 0; }