diff options
author | lloyd <[email protected]> | 2012-01-26 21:11:52 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-01-26 21:11:52 +0000 |
commit | cb8c64be095a0ef75beb621e8d669096efd7b8ae (patch) | |
tree | 5b1c20935afb94f6b02c238295c19373ac8f0e52 /doc | |
parent | 4b8786ad157e38b4143b0968c1ea1c83c2ee7388 (diff) |
Change callback interface to pass the Alert object itself instead
of just the type code.
Implement Alert::type_string
Diffstat (limited to 'doc')
-rw-r--r-- | doc/examples/asio_tls_server.cpp | 16 | ||||
-rw-r--r-- | doc/examples/tls_client.cpp | 6 | ||||
-rw-r--r-- | doc/examples/tls_server.cpp | 6 |
3 files changed, 14 insertions, 14 deletions
diff --git a/doc/examples/asio_tls_server.cpp b/doc/examples/asio_tls_server.cpp index 6d6c0e80e..58f59d968 100644 --- a/doc/examples/asio_tls_server.cpp +++ b/doc/examples/asio_tls_server.cpp @@ -84,7 +84,7 @@ class tls_server_session : public boost::enable_shared_from_this<tls_server_sess } catch(std::exception& e) { - printf("Failed - %s\n", e.what()); + std::cout << "Read failed " << e.what() << "\n"; stop(); return; } @@ -98,7 +98,6 @@ class tls_server_session : public boost::enable_shared_from_this<tls_server_sess else { stop(); - //printf("Error in read: %s\n", error.message().c_str()); } } @@ -114,7 +113,6 @@ class tls_server_session : public boost::enable_shared_from_this<tls_server_sess } else { - //printf("Error in write: %s\n", error.message().c_str()); stop(); } } @@ -139,12 +137,11 @@ class tls_server_session : public boost::enable_shared_from_this<tls_server_sess } } - void tls_data_recv(const byte buf[], size_t buf_len, Botan::u16bit alert_info) + void tls_data_recv(const byte buf[], size_t buf_len, Botan::TLS::Alert alert) { - if(buf_len == 0 && alert_info != Botan::TLS::NULL_ALERT) + if(alert.is_valid()) { - //printf("Alert: %d\n", alert_info); - if(alert_info == 0) + if(alert.type() == Botan::TLS::Alert::CLOSE_NOTIFY) { m_tls.close(); return; @@ -157,7 +154,8 @@ class tls_server_session : public boost::enable_shared_from_this<tls_server_sess out += "\r\n"; out += "HTTP/1.0 200 OK\r\n"; out += "Server: Botan ASIO test server\r\n"; - out += "Host: 192.168.10.5\r\n"; + if(m_hostname != "") + out += "Host: " + m_hostname + "\r\n"; out += "Content-Type: text/html\r\n"; out += "\r\n"; out += "<html><body>Greets. You said: "; @@ -172,6 +170,7 @@ class tls_server_session : public boost::enable_shared_from_this<tls_server_sess bool tls_handshake_complete(const Botan::TLS::Session& session) { + m_hostname = session.sni_hostname(); return true; } @@ -179,6 +178,7 @@ class tls_server_session : public boost::enable_shared_from_this<tls_server_sess tcp::socket m_socket; Botan::TLS::Server m_tls; + std::string m_hostname; unsigned char m_read_buf[Botan::TLS::MAX_TLS_RECORD_SIZE]; diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp index 80947af62..1cca002af 100644 --- a/doc/examples/tls_client.cpp +++ b/doc/examples/tls_client.cpp @@ -90,11 +90,11 @@ void socket_write(int sockfd, const byte buf[], size_t length) bool got_alert = false; -void process_data(const byte buf[], size_t buf_size, u16bit alert_info) +void process_data(const byte buf[], size_t buf_size, TLS::Alert alert) { - if(alert_info != TLS::NULL_ALERT) + if(alert.is_valid()) { - std::cout << "Alert: " << alert_info << "\n"; + std::cout << "Alert: " << alert.type_string() << "\n"; got_alert = true; } diff --git a/doc/examples/tls_server.cpp b/doc/examples/tls_server.cpp index e896b5bcc..a5f2c5d78 100644 --- a/doc/examples/tls_server.cpp +++ b/doc/examples/tls_server.cpp @@ -100,11 +100,11 @@ class Blocking_TLS_Server } } - void reader_fn(const byte buf[], size_t buf_len, u16bit alert_code) + void reader_fn(const byte buf[], size_t buf_len, TLS::Alert alert) { - if(buf_len == 0 && alert_code != TLS::NULL_ALERT) + if(alert.is_valid()) { - printf("Alert: %d\n", alert_code); + printf("Alert %s\n", alert.type_string().c_str()); //exit = true; } |