APPLEMAIL-24
Volker Birk 4 years ago
parent 56274f4ad1
commit 21cd35dfc7

@ -10,12 +10,13 @@
namespace pEp {
namespace http = boost::beast::http;
url_split split_url(string url, string default_port)
url_split split_url(string url)
{
static auto url_pattern =
"^(?<protocol>\\w+)://"
"((?<login>\\S+)(:(?<password>\\S+))?@)?"
"(?<host>[\\w.-]+)"
"(:(?<port>\\d+))?"
"(?<path>[^#\\s]+)?"
"(?<hash>#\\w+)?$";
@ -31,8 +32,6 @@ namespace pEp {
result.host = what["host"];
if (what["port"].matched)
result.port = what["port"];
else
result.port = default_port;
result.path = what["path"];
if (result.path == "")
result.path = "/";
@ -54,6 +53,8 @@ namespace pEp {
throw runtime_error("login data unsupported");
if (u.hash != "")
throw runtime_error("hash unsupported");
if (u.port =="")
u.port = "443";
if (_stream)
throw runtime_error("stream already open");
@ -79,6 +80,7 @@ namespace pEp {
_stream->handshake(ssl::stream_base::client);
}
catch (std::exception&) {
_stream->next_layer().shutdown(tcp::socket::shutdown_both, ec);
delete _stream;
_stream = nullptr;
throw;

@ -24,7 +24,7 @@ namespace pEp {
string hash;
};
url_split split_url(string url, string default_port="443");
url_split split_url(string url);
class HTTPSDevice : public io::device< io::source > {
boost::asio::io_context _ioc;
@ -38,9 +38,17 @@ namespace pEp {
public:
typedef io::source_tag category;
HTTPSDevice(string user_agent="pEp/1.0", int version=11)
HTTPSDevice(string url = "", string user_agent="pEp/1.0", int version=11)
: _user_agent(user_agent), _version(version), _stream(nullptr)
{
if (url != "")
open(url);
}
~HTTPSDevice()
{
if (_stream)
close();
}
void open(string url);

@ -5,7 +5,7 @@ include Makefile.conf
-include local.conf
CXXFLAGS += -std=c++14 -O0 -g
LDFLAGS += -lboost_regex-mt -lboost_iostreams-mt -lboost_system-mt
LDFLAGS += -lboost_regex-mt -lboost_iostreams-mt -lboost_system-mt -lssl -lcrypto
SOURCE=$(wildcard *.cc)
HEADERS=$(wildcard *.hh *.hxx)
@ -20,7 +20,7 @@ all: $(TARGET)
$(TARGET): $(WITHOUT_TESTS)
ar -rc $@ $^
.PHONY: clean install uninstall
.PHONY: clean install uninstall test
clean:
rm -f $(TARGET) $(OBJECTS) *.a
@ -40,3 +40,6 @@ test_split_url: test_split_url.o HTTPSStream.o
test: test_split_url
./test_split_url
tags: $(SOURCE) $(HEADERS)
ctags $(SOURCE) $(HEADERS)

@ -7,10 +7,10 @@ using namespace pEp;
int main()
{
auto url = "http://vb@dragon.pibit.ch/dingens#bumens";
auto url = "https://vb@dragon.pibit.ch:443/dingens#bumens";
auto split = split_url(url);
assert(split.protocol == "http");
assert(split.protocol == "https");
cout << "protocol: " << split.protocol << "\n";
assert(split.login == "vb");
cout << "login: " << split.login << "\n";
@ -18,7 +18,7 @@ int main()
cout << "password: " << split.password << "\n";
assert(split.host == "dragon.pibit.ch");
cout << "host: " << split.host << "\n";
assert(split.port == "80");
assert(split.port == "443");
cout << "port: " << split.port << "\n";
assert(split.path == "/dingens");
cout << "path: " << split.path << "\n";

Loading…
Cancel
Save