aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-27 14:10:37 +0000
committerlloyd <[email protected]>2015-01-27 14:10:37 +0000
commitb8fa304ec981d273c45d7ef31705d65ccfb00cc1 (patch)
tree86a0c03ddcf3f6b331a73170167bbf1e429e3d79 /src/cmd
parent5ca89c642f19b747b965a22db87e7af2d13d0f35 (diff)
Add typedefs for function signatures/types used in TLS for easier reading
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/tls_client.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/cmd/tls_client.cpp b/src/cmd/tls_client.cpp
index 543119fb9..903824a78 100644
--- a/src/cmd/tls_client.cpp
+++ b/src/cmd/tls_client.cpp
@@ -39,7 +39,7 @@ using namespace std::placeholders;
namespace {
-int connect_to_host(const std::string& host, u16bit port, const std::string& transport)
+int connect_to_host(const std::string& host, u16bit port, bool tcp)
{
hostent* host_addr = ::gethostbyname(host.c_str());
@@ -49,7 +49,7 @@ int connect_to_host(const std::string& host, u16bit port, const std::string& tra
if(host_addr->h_addrtype != AF_INET) // FIXME
throw std::runtime_error(host + " has IPv6 address, not supported");
- int type = (transport == "tcp") ? SOCK_STREAM : SOCK_DGRAM;
+ int type = tcp ? SOCK_STREAM : SOCK_DGRAM;
int fd = ::socket(PF_INET, type, 0);
if(fd == -1)
@@ -130,13 +130,6 @@ void process_data(const byte buf[], size_t buf_size)
std::cout << buf[i];
}
-std::string protocol_chooser(const std::vector<std::string>& protocols)
- {
- for(size_t i = 0; i != protocols.size(); ++i)
- std::cout << "Protocol " << i << " = " << protocols[i] << "\n";
- return "http/1.1";
- }
-
int tls_client(int argc, char* argv[])
{
if(argc != 2 && argc != 3 && argc != 4)
@@ -145,6 +138,9 @@ int tls_client(int argc, char* argv[])
return 1;
}
+ const bool request_protocol = true;
+ const std::string use_protocol = "http/1.1";
+
try
{
AutoSeeded_RNG rng;
@@ -167,14 +163,22 @@ int tls_client(int argc, char* argv[])
u32bit port = argc >= 3 ? Botan::to_u32bit(argv[2]) : 443;
const std::string transport = argc >= 4 ? argv[3] : "tcp";
- int sockfd = connect_to_host(host, port, transport);
+ const bool use_tcp = (transport == "tcp");
+
+ int sockfd = connect_to_host(host, port, use_tcp);
+
+ auto protocol_chooser = [use_protocol](const std::vector<std::string>& protocols) -> std::string {
+ for(size_t i = 0; i != protocols.size(); ++i)
+ std::cout << "Server offered protocol " << i << " = " << protocols[i] << "\n";
+ return use_protocol;
+ };
auto socket_write =
- (transport == "tcp") ?
+ use_tcp ?
std::bind(stream_socket_write, sockfd, _1, _2) :
std::bind(dgram_socket_write, sockfd, _1, _2);
- auto version = policy.latest_supported_version(transport != "tcp");
+ auto version = policy.latest_supported_version(!use_tcp);
TLS::Client client(socket_write,
process_data,