|
|
|
@ -17,10 +17,10 @@ Page::Page()
@@ -17,10 +17,10 @@ Page::Page()
|
|
|
|
|
// Define group actions
|
|
|
|
|
action_group->add_action( |
|
|
|
|
"update", |
|
|
|
|
sigc::mem_fun( |
|
|
|
|
* this, |
|
|
|
|
& Page::update |
|
|
|
|
) |
|
|
|
|
[this] |
|
|
|
|
{ |
|
|
|
|
Page::update(); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
insert_action_group( |
|
|
|
@ -46,12 +46,15 @@ Page::Page()
@@ -46,12 +46,15 @@ Page::Page()
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Page::~Page() = default; |
|
|
|
|
Page::~Page() |
|
|
|
|
{ |
|
|
|
|
delete navbar; |
|
|
|
|
delete content; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Public actions
|
|
|
|
|
void Page::update() |
|
|
|
|
{ |
|
|
|
|
// Route by request protocol
|
|
|
|
|
// Route by request scheme
|
|
|
|
|
if ("file" == navbar->get_request_scheme()) |
|
|
|
|
{ |
|
|
|
|
// @TODO
|
|
|
|
@ -59,55 +62,61 @@ void Page::update()
@@ -59,55 +62,61 @@ void Page::update()
|
|
|
|
|
|
|
|
|
|
else if ("gemini" == navbar->get_request_scheme()) |
|
|
|
|
{ |
|
|
|
|
connect( |
|
|
|
|
navbar->get_request_host(), |
|
|
|
|
navbar->get_request_port().empty() ? 1965 : stoi( |
|
|
|
|
navbar->get_request_port() |
|
|
|
|
) |
|
|
|
|
// Create new socket connection
|
|
|
|
|
socket_client = Gio::SocketClient::create(); |
|
|
|
|
|
|
|
|
|
socket_client->set_tls( |
|
|
|
|
true |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// @TODO
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
socket_client->set_tls_validation_flags( |
|
|
|
|
Gio::TlsCertificateFlags::NO_FLAGS |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Private helpers
|
|
|
|
|
void Page::connect( |
|
|
|
|
const std::string & host, |
|
|
|
|
int port |
|
|
|
|
) { |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
socket_client = Gio::SocketClient::create(); |
|
|
|
|
socket_client->set_timeout( |
|
|
|
|
15 // @TODO
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
socket_client->connect_to_host_async( |
|
|
|
|
host, |
|
|
|
|
port, |
|
|
|
|
navbar->get_request_host(), |
|
|
|
|
navbar->get_request_port().empty() ? 1965 : stoi( |
|
|
|
|
navbar->get_request_port() |
|
|
|
|
), |
|
|
|
|
[this](const Glib::RefPtr<Gio::AsyncResult> & result) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
auto socket = socket_client->connect_finish( |
|
|
|
|
socket_connection = socket_client->connect_to_host_finish( |
|
|
|
|
result |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// @TODO read/write data
|
|
|
|
|
// Request
|
|
|
|
|
const std::string request = navbar->get_request() + "\r\n"; |
|
|
|
|
|
|
|
|
|
socket->close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
catch (const Glib::Error & exception) |
|
|
|
|
socket_connection->get_output_stream()->write_async( |
|
|
|
|
request.data(), |
|
|
|
|
request.size(), |
|
|
|
|
[this](const Glib::RefPtr<Gio::AsyncResult> & result) |
|
|
|
|
{ |
|
|
|
|
// @TODO exception.what();
|
|
|
|
|
// Response
|
|
|
|
|
socket_connection->get_input_stream()->read_all_async( // | read_async
|
|
|
|
|
buffer, |
|
|
|
|
sizeof(buffer) - 1, |
|
|
|
|
[this](const Glib::RefPtr<Gio::AsyncResult> & result) |
|
|
|
|
{ |
|
|
|
|
content->set( |
|
|
|
|
buffer |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
socket_connection->close(); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
catch (const std::exception & exception) |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// @TODO exception.what();
|
|
|
|
|
// @TODO
|
|
|
|
|
} |
|
|
|
|
} |