Fork for poking around in the original "client implementation for p≡p update server".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.9 KiB

// this file is under GNU General Public License 3.0
// see LICENSE.txt
#pragma once
#include <iostream>
#include <fstream>
#include <functional>
#include <boost/asio.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/http/message.hpp>
namespace pEp {
using namespace std;
namespace io = boost::iostreams;
using tcp = boost::asio::ip::tcp;
namespace ssl = boost::asio::ssl;
namespace http = boost::beast::http;
typedef function< void() > notifyRead_t;
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::source {
boost::asio::io_context _ioc;
ssl::stream<tcp::socket> *_stream;
string _url;
string _user_agent;
int _version;
string _host;
http::response_parser<http::file_body> _parser;
ifstream _temp;
string _filename;
notifyRead_t notifyRead;
HTTPSDevice(string url = "", string user_agent="pEp/1.0", int
HTTPSDevice(const HTTPSDevice& second);
void open(string url = "", notifyRead_t notifyRead = nullptr);
void get(string path, notifyRead_t notifyRead = nullptr);
void close();
const http::fields& header() const { return _parser.get(); }
const auto& body() const { return _parser.get().body(); }
string filename() const { return _filename; }
streamsize read(char* s, streamsize n);
const char *temp_file_path()
return "encrypted.tmp";
typedef io::stream< HTTPSDevice > HTTPSStream;